@@ -19,18 +19,26 @@ class ImportExportPage extends StatefulWidget {
19
19
20
20
class _ImportExportPageState extends State <ImportExportPage > {
21
21
bool _loading = false ;
22
- String content = '' ;
23
22
final GlobalKey <ScaffoldState > _scaffoldKey = new GlobalKey <ScaffoldState >();
23
+ final TextEditingController __textEditingController = TextEditingController (text: '' );
24
24
25
25
@override
26
26
void initState () {
27
27
super .initState ();
28
28
loadData ();
29
29
}
30
30
31
+ @override
32
+ void dispose () {
33
+ __textEditingController.dispose ();
34
+ super .dispose ();
35
+ }
36
+
31
37
void loadData () async {
32
- _loading = true ;
33
- content = JsonEncoder .withIndent (" " ).convert (widget.questions);
38
+ setState (() {
39
+ _loading = true ;
40
+ });
41
+ __textEditingController.text = JsonEncoder .withIndent (" " ).convert (widget.questions);
34
42
setState (() {
35
43
_loading = false ;
36
44
});
@@ -53,7 +61,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
53
61
children: [
54
62
RaisedButton .icon (
55
63
onPressed: () async {
56
- List <dynamic > data = json.decode (content );
64
+ List <dynamic > data = json.decode (__textEditingController.text );
57
65
var questions = data.map ((item) => Question .fromJson (item)).toList ();
58
66
var prefs = await LocalStorage .getInstance ();
59
67
var rawTemplate = prefs.getString ('rawTemplate' );
@@ -81,7 +89,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
81
89
label: Text ('copy as raw' )),
82
90
RaisedButton .icon (
83
91
onPressed: () async {
84
- List <dynamic > data = json.decode (content );
92
+ List <dynamic > data = json.decode (__textEditingController.text );
85
93
var questions = data.map ((item) => Question .fromJson (item)).toList ();
86
94
var prefs = await LocalStorage .getInstance ();
87
95
var programTemplate = prefs.getString ('programTemplate' );
@@ -114,10 +122,12 @@ class _ImportExportPageState extends State<ImportExportPage> {
114
122
children: [
115
123
RaisedButton .icon (
116
124
onPressed: () async {
117
- List <dynamic > data = json.decode (content);
118
- var questions = data.map ((item) => json.encode (item)).toList ();
119
- var prefs = await LocalStorage .getInstance ();
120
- prefs.setStringList ('questions' , questions);
125
+ List <dynamic > data = json.decode (__textEditingController.text);
126
+ // var questions = data.map((item) => json.encode(item)).toList();
127
+ // var prefs = await LocalStorage.getInstance();
128
+ // prefs.setStringList('questions', questions);
129
+ var questions = data.map ((item) => Question .fromJson (item)).toList ();
130
+ Navigator .of (context).pop (questions);
121
131
_scaffoldKey.currentState.showSnackBar (
122
132
SnackBar (
123
133
content: Text ('import successfully!' ),
@@ -128,7 +138,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
128
138
label: Text ('import' )),
129
139
RaisedButton .icon (
130
140
onPressed: () async {
131
- Clipboard .setData (ClipboardData (text: content ));
141
+ Clipboard .setData (ClipboardData (text: __textEditingController.text ));
132
142
_scaffoldKey.currentState.showSnackBar (
133
143
SnackBar (
134
144
content: Text ('export successfully, copied to the clipboard!' ),
@@ -141,20 +151,10 @@ class _ImportExportPageState extends State<ImportExportPage> {
141
151
),
142
152
Padding (
143
153
padding: const EdgeInsets .all (defaultMargin),
144
- child: Row (
145
- children: [
146
- Expanded (
147
- child: HighlightView (
148
- content,
149
- readOnly: false ,
150
- language: 'json' ,
151
- theme: themeMap['solarized-light' ],
152
- padding: EdgeInsets .all (defaultMargin),
153
- textStyle:
154
- TextStyle (fontFamily: 'SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace' ),
155
- ),
156
- ),
157
- ],
154
+ child: TextField (
155
+ maxLines: 10 ,
156
+ controller: __textEditingController,
157
+ decoration: InputDecoration (labelText: 'Content' ),
158
158
),
159
159
),
160
160
],
0 commit comments