Skip to content

Commit

Permalink
adding importing glowbom files
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-i committed Apr 18, 2023
1 parent 164e952 commit fdc6378
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/assets/talk.glowbom
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"title":"Glowby","main_color":"Black","conclusion":"Please send us your information and we'll come back to you shortly!","start_over":"","show_number_result":true,"show_percentage_result":true,"voice":true,"questions":[{"title":"","description":"Hello","buttonsTexts":["Hello!","Hi!","Hi there!","Hey, What's up?"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]},{"title":"","description":"How's it going?","buttonsTexts":["I'm ok.","I'm doing quite well, thank you.","Pretty good. How goes it for you?","I'm good, thanks for asking!"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]},{"title":"","description":"What's up?","buttonsTexts":["Not much. Just enjoying my time on this sim.","You just summed up my worldview.","Nothing really, just keeping busy.","I can't tell you!"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]}],"dnsgs":true}
{"title":"Glowby","main_color":"Black","conclusion":"Please send us your information and we'll come back to you shortly!","start_over":"Glowby","show_number_result":true,"show_percentage_result":true,"voice":true,"questions":[{"title":"","description":"Hello","buttonsTexts":["Hello!","Hi!","Hi there!","Hey, What's up?"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]},{"title":"","description":"How's it going?","buttonsTexts":["I'm ok.","I'm doing quite well, thank you.","Pretty good. How goes it for you?","I'm good, thanks for asking!"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]},{"title":"","description":"What's up?","buttonsTexts":["Not much. Just enjoying my time on this sim.","You just summed up my worldview.","Nothing really, just keeping busy.","I can't tell you!"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]}],"dnsgs":true}
88 changes: 65 additions & 23 deletions app/lib/preset_talk.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'color_utils.dart';
import 'chat_screen.dart';
Expand All @@ -11,6 +13,7 @@ class _TalkState extends State<Talk> {
String? _mainColor;
bool? _voice = false;
List<Map<String, Object>> _questions = [];
GlobalKey<ChatScreenState> chatScreenKey = GlobalKey();

_TalkState(this._content);

Expand Down Expand Up @@ -47,6 +50,39 @@ class _TalkState extends State<Talk> {
}
}

void _startFilePicker() async {
try {
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['glowbom'], // Limit the file extension to 'glowbom'
);

if (result != null) {
PlatformFile file = result.files.first;
Uint8List? fileBytes = file.bytes;
if (fileBytes != null) {
String content =
utf8.decode(fileBytes); // Decode the Uint8List to a String
Map<String, dynamic> fileContent = json.decode(content);

// Do something with the file content, e.g., update the questions
setState(() {
_content = fileContent;
_title = _content['title'];
_mainColor = _content['main_color'] ?? 'Blue';
_voice = _content['voice'] ?? false;
_questions = buildQuestions(_content['questions']);
});

print(_content);
print('name = ${_content['start_over']}');
}
}
} catch (e) {
print('Error: $e'); // Log the exception
}
}

List<Map<String, Object>> buildQuestions(List<dynamic> questionsData) {
List<Map<String, Object>> questions =
List<Map<String, Object>>.empty(growable: true);
Expand Down Expand Up @@ -110,31 +146,37 @@ class _TalkState extends State<Talk> {
: Colors.grey),
),
home: Scaffold(
appBar: AppBar(
title: Text(
_title != null ? _title! : 'Chat App',
style: TextStyle(
color: Colors.white,
),
appBar: AppBar(
title: Text(
_title != null ? _title! : 'Chat App',
style: TextStyle(
color: Colors.white,
),
centerTitle: true,
),
body: _appScreen == 'Loading'
? Center(
child: Text('Loading...'),
)
: _appScreen == 'Glowbom'
? Center(
child:
const Image(image: AssetImage('assets/glowbom.png')),
)
: ChatScreen(
_content != null && _content.containsKey('start_over')
? _content['start_over']
: 'AI',
_questions,
_voice!,
)),
centerTitle: true,
actions: [
IconButton(
icon: Icon(Icons.file_upload),
onPressed: _startFilePicker,
),
],
),
body: _appScreen == 'Loading'
? Center(
child: Text('Loading...'),
)
: _appScreen == 'Glowbom'
? Center(
child: const Image(image: AssetImage('assets/glowbom.png')),
)
: ChatScreen(
_content != null && _content.containsKey('start_over')
? _content['start_over']
: 'AI',
_questions,
_voice!,
),
),
);
}
}
Expand Down
1 change: 1 addition & 0 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies:
http: ^0.13.5
shared_preferences: ^2.1.0
flutter_secure_storage: ^8.0.0
file_picker: ^5.2.9

flutter:
sdk: flutter
Expand Down

0 comments on commit fdc6378

Please sign in to comment.