fix msg
This commit is contained in:
@@ -8,27 +8,28 @@ import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_icons_null_safety/flutter_icons_null_safety.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:zefyr/zefyr.dart';
|
||||
// import 'package:zefyr/zefyr.dart';
|
||||
|
||||
typedef void ProfileCallback();
|
||||
|
||||
class TermEdit extends StatefulWidget {
|
||||
final Term term;
|
||||
TermEdit({this.term});
|
||||
TermEdit({required this.term});
|
||||
@override
|
||||
_TermEditState createState() => _TermEditState();
|
||||
}
|
||||
|
||||
class _TermEditState extends State<TermEdit> {
|
||||
/// Allows to control the editor and the document.
|
||||
ZefyrController _controllerEng;
|
||||
ZefyrController _controllerMm;
|
||||
// ZefyrController _controllerEng;
|
||||
// ZefyrController _controllerMm;
|
||||
|
||||
/// Zefyr editor like any other input field requires a focus node.
|
||||
FocusNode _focusNodeEng;
|
||||
FocusNode _focusNodeMm;
|
||||
bool _isLoading;
|
||||
// FocusNode _focusNodeEng;
|
||||
// FocusNode _focusNodeMm;
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -36,23 +37,23 @@ class _TermEditState extends State<TermEdit> {
|
||||
_isLoading = false;
|
||||
|
||||
// Here we must load the document and pass it to Zefyr controller.
|
||||
_controllerEng = ZefyrController(_loadDocument(widget.term.termEng));
|
||||
_controllerMm = ZefyrController(_loadDocument(widget.term.termMm));
|
||||
_focusNodeEng = FocusNode();
|
||||
_focusNodeMm = FocusNode();
|
||||
// _controllerEng = ZefyrController(_loadDocument(widget.term.termEng));
|
||||
// _controllerMm = ZefyrController(_loadDocument(widget.term.termMm));
|
||||
// _focusNodeEng = FocusNode();
|
||||
// _focusNodeMm = FocusNode();
|
||||
}
|
||||
|
||||
/// Loads the document to be edited in Zefyr.
|
||||
NotusDocument _loadDocument(String data) {
|
||||
NotusDocument doc;
|
||||
try {
|
||||
doc = NotusDocument.fromJson(jsonDecode(data));
|
||||
} catch (e) {}
|
||||
if (doc == null) {
|
||||
doc = NotusDocument();
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
// NotusDocument _loadDocument(String data) {
|
||||
// NotusDocument doc;
|
||||
// try {
|
||||
// doc = NotusDocument.fromJson(jsonDecode(data));
|
||||
// } catch (e) {}
|
||||
// if (doc == null) {
|
||||
// doc = NotusDocument();
|
||||
// }
|
||||
// return doc;
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -115,8 +116,8 @@ class _TermEditState extends State<TermEdit> {
|
||||
height: MediaQuery.of(context).size.height - 200,
|
||||
child: TabBarView(
|
||||
children: [
|
||||
textEditor(_controllerEng, _focusNodeEng),
|
||||
textEditor(_controllerMm, _focusNodeMm),
|
||||
// textEditor(_controllerEng, _focusNodeEng),
|
||||
// textEditor(_controllerMm, _focusNodeMm),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -128,35 +129,35 @@ class _TermEditState extends State<TermEdit> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget textEditor(ZefyrController controller, FocusNode focusNode) {
|
||||
return ListView(
|
||||
children: [
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height - 200,
|
||||
child: ZefyrScaffold(
|
||||
child: ZefyrTheme(
|
||||
data: ZefyrThemeData().copyWith(
|
||||
defaultLineTheme: LineTheme(
|
||||
padding: EdgeInsets.all(0),
|
||||
textStyle: TextStyle(fontFamily: "Myanmar3"),
|
||||
),
|
||||
),
|
||||
child: ZefyrEditor(
|
||||
autofocus: false,
|
||||
padding: EdgeInsets.all(16),
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// savebtn,
|
||||
SizedBox(
|
||||
height: 10,
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
// Widget textEditor(ZefyrController controller, FocusNode focusNode) {
|
||||
// return ListView(
|
||||
// children: [
|
||||
// Container(
|
||||
// height: MediaQuery.of(context).size.height - 200,
|
||||
// child: ZefyrScaffold(
|
||||
// child: ZefyrTheme(
|
||||
// data: ZefyrThemeData().copyWith(
|
||||
// defaultLineTheme: LineTheme(
|
||||
// padding: EdgeInsets.all(0),
|
||||
// textStyle: TextStyle(fontFamily: "Myanmar3"),
|
||||
// ),
|
||||
// ),
|
||||
// child: ZefyrEditor(
|
||||
// autofocus: false,
|
||||
// padding: EdgeInsets.all(16),
|
||||
// controller: controller,
|
||||
// focusNode: focusNode,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// // savebtn,
|
||||
// SizedBox(
|
||||
// height: 10,
|
||||
// )
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
|
||||
_unfocus() {
|
||||
FocusScope.of(context).unfocus();
|
||||
@@ -167,11 +168,11 @@ class _TermEditState extends State<TermEdit> {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
final contentsEng = jsonEncode(_controllerEng.document);
|
||||
final contentsMm = jsonEncode(_controllerMm.document);
|
||||
print('contents => $contentsEng');
|
||||
TermModel termModel = Provider.of<TermModel>(context, listen: false);
|
||||
await termModel.saveTerm(Term(termEng: contentsEng, termMm: contentsMm));
|
||||
// final contentsEng = jsonEncode(_controllerEng.document);
|
||||
// final contentsMm = jsonEncode(_controllerMm.document);
|
||||
// print('contents => $contentsEng');
|
||||
// TermModel termModel = Provider.of<TermModel>(context, listen: false);
|
||||
// await termModel.saveTerm(Term(termEng: contentsEng, termMm: contentsMm));
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
|
||||
@@ -10,46 +10,46 @@ import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:zefyr/zefyr.dart';
|
||||
// import 'package:zefyr/zefyr.dart';
|
||||
|
||||
typedef void ProfileCallback();
|
||||
|
||||
class TermPage extends StatefulWidget {
|
||||
const TermPage({
|
||||
Key key,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
@override
|
||||
_TermPageState createState() => _TermPageState();
|
||||
}
|
||||
|
||||
class _TermPageState extends State<TermPage> {
|
||||
ZefyrController _controller;
|
||||
FocusNode _focusNode;
|
||||
NotusDocument document = new NotusDocument();
|
||||
// ZefyrController _controller;
|
||||
// FocusNode _focusNode;
|
||||
// NotusDocument document = new NotusDocument();
|
||||
bool isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_focusNode = FocusNode();
|
||||
// _focusNode = FocusNode();
|
||||
}
|
||||
|
||||
NotusDocument _loadDocument(Setting setting) {
|
||||
bool isEng = Provider.of<LanguageModel>(context).isEng;
|
||||
String term = isEng ? setting.termsEng : setting.termsMm;
|
||||
NotusDocument doc;
|
||||
try {
|
||||
doc = NotusDocument.fromJson(jsonDecode(term));
|
||||
} catch (e) {}
|
||||
if (doc == null) {
|
||||
doc = NotusDocument();
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
// NotusDocument _loadDocument(Setting setting) {
|
||||
// bool isEng = Provider.of<LanguageModel>(context).isEng;
|
||||
// String term = isEng ? setting.termsEng : setting.termsMm;
|
||||
// NotusDocument doc;
|
||||
// try {
|
||||
// doc = NotusDocument.fromJson(jsonDecode(term));
|
||||
// } catch (e) {}
|
||||
// if (doc == null) {
|
||||
// doc = NotusDocument();
|
||||
// }
|
||||
// return doc;
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Setting setting = Provider.of<MainModel>(context).setting;
|
||||
Setting? setting = Provider.of<MainModel>(context).setting;
|
||||
bool isEditable = context.select((MainModel m) => m.termEditable());
|
||||
|
||||
return Scaffold(
|
||||
@@ -76,7 +76,7 @@ class _TermPageState extends State<TermPage> {
|
||||
onPressed: () =>
|
||||
Navigator.of(context).push<void>(CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
TermEdit(term: Term.fromSetting(setting)),
|
||||
TermEdit(term: Term.fromSetting(setting!)),
|
||||
)),
|
||||
icon: Icon(
|
||||
CupertinoIcons.pen,
|
||||
@@ -85,25 +85,25 @@ class _TermPageState extends State<TermPage> {
|
||||
]
|
||||
: [],
|
||||
),
|
||||
body: ZefyrTheme(
|
||||
data: ZefyrThemeData().copyWith(
|
||||
defaultLineTheme: LineTheme(
|
||||
padding: EdgeInsets.all(0),
|
||||
textStyle: TextStyle(fontFamily: "Myanmar3"),
|
||||
),
|
||||
),
|
||||
// data: ZefyrThemeData().copyWith(
|
||||
// defaultLineTheme: LineTheme(
|
||||
// textStyle: TextStyle(color: Colors.black),
|
||||
// padding: EdgeInsets.all(0))),
|
||||
child: ZefyrScaffold(
|
||||
child: ZefyrEditor(
|
||||
mode: ZefyrMode.view,
|
||||
padding: EdgeInsets.all(16),
|
||||
controller: ZefyrController(_loadDocument(setting)),
|
||||
focusNode: _focusNode,
|
||||
),
|
||||
)),
|
||||
// body: ZefyrTheme(
|
||||
// data: ZefyrThemeData().copyWith(
|
||||
// defaultLineTheme: LineTheme(
|
||||
// padding: EdgeInsets.all(0),
|
||||
// textStyle: TextStyle(fontFamily: "Myanmar3"),
|
||||
// ),
|
||||
// ),
|
||||
// // data: ZefyrThemeData().copyWith(
|
||||
// // defaultLineTheme: LineTheme(
|
||||
// // textStyle: TextStyle(color: Colors.black),
|
||||
// // padding: EdgeInsets.all(0))),
|
||||
// child: ZefyrScaffold(
|
||||
// child: ZefyrEditor(
|
||||
// mode: ZefyrMode.view,
|
||||
// padding: EdgeInsets.all(16),
|
||||
// controller: ZefyrController(_loadDocument(setting)),
|
||||
// focusNode: _focusNode,
|
||||
// ),
|
||||
// )),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user