From fdc63784ac4cb3572c42e6f40ddc8825655af618 Mon Sep 17 00:00:00 2001 From: Jacob Date: Mon, 17 Apr 2023 21:14:33 -0700 Subject: [PATCH] adding importing glowbom files --- app/assets/talk.glowbom | 2 +- app/lib/preset_talk.dart | 88 +++++++++++++++++++++++++++++----------- app/pubspec.yaml | 1 + 3 files changed, 67 insertions(+), 24 deletions(-) diff --git a/app/assets/talk.glowbom b/app/assets/talk.glowbom index 98bf586..ef6fdc8 100644 --- a/app/assets/talk.glowbom +++ b/app/assets/talk.glowbom @@ -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} \ No newline at end of file +{"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} \ No newline at end of file diff --git a/app/lib/preset_talk.dart b/app/lib/preset_talk.dart index e37bfc8..5473e9b 100644 --- a/app/lib/preset_talk.dart +++ b/app/lib/preset_talk.dart @@ -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'; @@ -11,6 +13,7 @@ class _TalkState extends State { String? _mainColor; bool? _voice = false; List> _questions = []; + GlobalKey chatScreenKey = GlobalKey(); _TalkState(this._content); @@ -47,6 +50,39 @@ class _TalkState extends State { } } + 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 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> buildQuestions(List questionsData) { List> questions = List>.empty(growable: true); @@ -110,31 +146,37 @@ class _TalkState extends State { : 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!, + ), + ), ); } } diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 08914ee..5798125 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -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