add markdown for term
This commit is contained in:
@@ -1,174 +0,0 @@
|
||||
import 'package:fcs/domain/vo/term.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/main/util.dart';
|
||||
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:zefyrka/zefyrka.dart';
|
||||
// import 'package:zefyr/zefyr.dart';
|
||||
|
||||
typedef void ProfileCallback();
|
||||
|
||||
class TermEdit extends StatefulWidget {
|
||||
final Term? term;
|
||||
TermEdit({required this.term});
|
||||
@override
|
||||
_TermEditState createState() => _TermEditState();
|
||||
}
|
||||
|
||||
class _TermEditState extends State<TermEdit> {
|
||||
/// Allows to control the editor and the document.
|
||||
// late ZefyrController _controllerEng;
|
||||
// late ZefyrController _controllerMm;
|
||||
|
||||
/// Zefyr editor like any other input field requires a focus node.
|
||||
late FocusNode _focusNodeEng;
|
||||
late FocusNode _focusNodeMm;
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_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();
|
||||
}
|
||||
|
||||
/// Loads the document to be edited in Zefyr.
|
||||
// NotusDocument _loadDocument(String data) {
|
||||
// late NotusDocument doc;
|
||||
// try {
|
||||
// doc = NotusDocument.fromJson(jsonDecode(data));
|
||||
// } catch (e) {}
|
||||
// if (doc == null) {
|
||||
// doc = NotusDocument();
|
||||
// }
|
||||
// return doc;
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final savebtn =
|
||||
fcsButton(context, getLocalString(context, "btn.save"), callack: _save);
|
||||
|
||||
return DefaultTabController(
|
||||
length: 2,
|
||||
child: LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: LocalLargeTitle(
|
||||
context,
|
||||
"term",
|
||||
color: primaryColor,
|
||||
),
|
||||
leading: IconButton(
|
||||
icon: Icon(CupertinoIcons.back, color: primaryColor, size: 25),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
shadowColor: Colors.transparent,
|
||||
backgroundColor: Colors.white,
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: _unfocus,
|
||||
icon: Icon(Icons.check, color: primaryColor))
|
||||
],
|
||||
bottom: TabBar.secondary(
|
||||
indicatorColor: primaryColor,
|
||||
onTap: (index) {
|
||||
if (index == 0) {
|
||||
_focusNodeEng = new FocusNode();
|
||||
FocusScope.of(context).requestFocus(_focusNodeEng);
|
||||
} else {
|
||||
_focusNodeMm = new FocusNode();
|
||||
FocusScope.of(context).requestFocus(_focusNodeMm);
|
||||
}
|
||||
},
|
||||
tabs: [
|
||||
Tab(
|
||||
icon: Image.asset(
|
||||
'icons/flags/png/us.png',
|
||||
package: 'country_icons',
|
||||
fit: BoxFit.fitWidth,
|
||||
width: 25,
|
||||
)),
|
||||
Tab(
|
||||
icon: Image.asset(
|
||||
'icons/flags/png/mm.png',
|
||||
package: 'country_icons',
|
||||
fit: BoxFit.fitWidth,
|
||||
width: 25,
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height - 200,
|
||||
child: TabBarView(
|
||||
children: [
|
||||
const SizedBox(),
|
||||
const SizedBox(),
|
||||
// textEditor(_controllerEng, _focusNodeEng),
|
||||
// textEditor(_controllerMm, _focusNodeMm),
|
||||
],
|
||||
),
|
||||
),
|
||||
savebtn,
|
||||
const SizedBox(height: 20)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Widget textEditor(ZefyrController controller, FocusNode focusNode) {
|
||||
// return ListView(
|
||||
// children: [
|
||||
// Container(
|
||||
// height: MediaQuery.of(context).size.height - 200,
|
||||
// child: ZefyrEditor(
|
||||
// autofocus: false,
|
||||
// padding: EdgeInsets.all(16),
|
||||
// controller: controller,
|
||||
// focusNode: focusNode,
|
||||
// ),
|
||||
// ),
|
||||
// SizedBox(
|
||||
// height: 10,
|
||||
// )
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
|
||||
_unfocus() {
|
||||
FocusScope.of(context).unfocus();
|
||||
}
|
||||
|
||||
_save() async {
|
||||
setState(() {
|
||||
_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));
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
213
lib/pages/term/term_editor.dart
Normal file
213
lib/pages/term/term_editor.dart
Normal file
@@ -0,0 +1,213 @@
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import '../../domain/vo/term.dart';
|
||||
import '../main/util.dart';
|
||||
import '../widgets/local_text.dart';
|
||||
|
||||
class TermEditor extends StatefulWidget {
|
||||
final Term term;
|
||||
const TermEditor({super.key, required this.term});
|
||||
|
||||
@override
|
||||
State<TermEditor> createState() => _TermEditorState();
|
||||
}
|
||||
|
||||
class _TermEditorState extends State<TermEditor> {
|
||||
int selectedIndex = 0;
|
||||
final List<bool> _selectedIcon = <bool>[true, false];
|
||||
List<Widget> icons = <Widget>[
|
||||
const Icon(Icons.edit),
|
||||
const Icon(Icons.preview_outlined),
|
||||
];
|
||||
bool isEdit = true;
|
||||
TextEditingController mmController = TextEditingController();
|
||||
TextEditingController enController = TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
enController.text = widget.term.termEng ?? "";
|
||||
mmController.text = widget.term.termMm ?? "";
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
enController.dispose();
|
||||
mmController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final toggleBtn = ToggleButtons(
|
||||
direction: Axis.horizontal,
|
||||
onPressed: (int index) {
|
||||
setState(() {
|
||||
for (int i = 0; i < _selectedIcon.length; i++) {
|
||||
_selectedIcon[i] = !_selectedIcon[i];
|
||||
isEdit = (_selectedIcon[0] == true) ? true : false;
|
||||
}
|
||||
});
|
||||
},
|
||||
borderRadius: const BorderRadius.all(Radius.circular(5)),
|
||||
borderColor: primaryColor.withOpacity(0.3),
|
||||
selectedBorderColor: Colors.white,
|
||||
fillColor: primaryColor,
|
||||
color: primaryColor,
|
||||
isSelected: _selectedIcon,
|
||||
constraints: const BoxConstraints(minHeight: 20, minWidth: 40),
|
||||
children: icons,
|
||||
);
|
||||
|
||||
final savebtn = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: fcsButton(context, getLocalString(context, "btn.save"),
|
||||
callack: _save),
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: DefaultTabController(
|
||||
length: 2,
|
||||
initialIndex: selectedIndex,
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
appBar: AppBar(
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
leading: IconButton(
|
||||
splashRadius: 25,
|
||||
icon: const Icon(CupertinoIcons.back,
|
||||
color: primaryColor, size: 25),
|
||||
onPressed: () => Navigator.pop(context)),
|
||||
shadowColor: Colors.transparent,
|
||||
backgroundColor: Colors.white,
|
||||
title:
|
||||
LocalText(context, 'term', fontSize: 20, color: primaryColor),
|
||||
bottom: TabBar.secondary(
|
||||
indicatorColor: primaryColor,
|
||||
labelColor: primaryColor,
|
||||
labelStyle:
|
||||
const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
|
||||
unselectedLabelColor: Colors.grey,
|
||||
unselectedLabelStyle:
|
||||
const TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
|
||||
onTap: (index) {
|
||||
selectedIndex = index;
|
||||
},
|
||||
tabs: [Tab(text: "English"), Tab(text: "Myanmar")]),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 20), child: toggleBtn)
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: ScrollConfiguration(
|
||||
behavior: const ScrollBehavior().copyWith(overscroll: false),
|
||||
child: ListView(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: MediaQuery.of(context).size.height - 210,
|
||||
child: TabBarView(
|
||||
children: [
|
||||
isEdit
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(15),
|
||||
child: TextField(
|
||||
autofocus: true,
|
||||
controller: enController,
|
||||
style: TextStyle(
|
||||
fontSize: 15, color: Colors.black87),
|
||||
decoration: const InputDecoration(
|
||||
border: InputBorder.none),
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.multiline,
|
||||
maxLines: null,
|
||||
readOnly: isEdit ? false : true,
|
||||
),
|
||||
)
|
||||
: Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(top: 15, bottom: 15),
|
||||
child: Markdown(
|
||||
shrinkWrap: true,
|
||||
softLineBreak: true,
|
||||
physics: const BouncingScrollPhysics(),
|
||||
data: enController.text
|
||||
.replaceAll("\\n", '\n'),
|
||||
styleSheet: MarkdownStyleSheet.fromTheme(
|
||||
ThemeData(
|
||||
textTheme: const TextTheme(
|
||||
bodyMedium: TextStyle(
|
||||
fontSize: 15,
|
||||
color: Colors.black87))))),
|
||||
),
|
||||
isEdit
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(15),
|
||||
child: TextField(
|
||||
style: TextStyle(
|
||||
fontSize: 14, color: Colors.black87),
|
||||
autofocus: true,
|
||||
controller: mmController,
|
||||
decoration: const InputDecoration(
|
||||
border: InputBorder.none),
|
||||
cursorColor: primaryColor,
|
||||
keyboardType: TextInputType.multiline,
|
||||
maxLines: null,
|
||||
readOnly: isEdit ? false : true,
|
||||
),
|
||||
)
|
||||
: Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(top: 15, bottom: 15),
|
||||
child: Markdown(
|
||||
shrinkWrap: true,
|
||||
softLineBreak: true,
|
||||
physics: const BouncingScrollPhysics(),
|
||||
data: mmController.text
|
||||
.replaceAll("\\n", '\n'),
|
||||
styleSheet: MarkdownStyleSheet.fromTheme(
|
||||
ThemeData(
|
||||
textTheme: const TextTheme(
|
||||
bodyMedium: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.black87))))),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
savebtn,
|
||||
const SizedBox(height: 20)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_save() async {
|
||||
setState(() {
|
||||
_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));
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,52 +2,28 @@ import 'package:fcs/domain/entities/setting.dart';
|
||||
import 'package:fcs/domain/vo/term.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/term/term_edit.dart';
|
||||
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
// import 'package:zefyrka/zefyrka.dart';
|
||||
|
||||
typedef void ProfileCallback();
|
||||
import '../main/model/language_model.dart';
|
||||
import 'term_editor.dart';
|
||||
|
||||
class TermPage extends StatefulWidget {
|
||||
const TermPage({
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
const TermPage({Key? key}) : super(key: key);
|
||||
@override
|
||||
_TermPageState createState() => _TermPageState();
|
||||
}
|
||||
|
||||
class _TermPageState extends State<TermPage> {
|
||||
// late ZefyrController _controller;
|
||||
// late FocusNode _focusNode;
|
||||
// late NotusDocument document = new NotusDocument();
|
||||
bool isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// _focusNode = FocusNode();
|
||||
}
|
||||
|
||||
// NotusDocument _loadDocument(Setting? setting) {
|
||||
// bool isEng = Provider.of<LanguageModel>(context).isEng;
|
||||
// String? term = isEng ? (setting!.termsEng ?? "") : (setting!.termsMm ?? "");
|
||||
// late NotusDocument doc;
|
||||
// try {
|
||||
// doc = NotusDocument.fromJson(jsonDecode(term));
|
||||
// } catch (e) {}
|
||||
// if (doc == null) {
|
||||
// doc = NotusDocument();
|
||||
// }
|
||||
// return doc;
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool isEng = Provider.of<LanguageModel>(context).isEng;
|
||||
Setting? setting = Provider.of<MainModel>(context).setting;
|
||||
bool isEditable = context.select((MainModel m) => m.termEditable());
|
||||
String? term = isEng ? (setting!.termsEng ?? "") : (setting!.termsMm ?? "");
|
||||
|
||||
return Scaffold(
|
||||
appBar: LocalAppBar(
|
||||
@@ -58,20 +34,25 @@ class _TermPageState extends State<TermPage> {
|
||||
actions: isEditable
|
||||
? [
|
||||
IconButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(context).push<void>(CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
TermEdit(term: Term.fromSetting(setting!)),
|
||||
)),
|
||||
onPressed: () {
|
||||
Navigator.of(context).push<void>(CupertinoPageRoute(
|
||||
builder: (context) =>
|
||||
TermEditor(term: Term.fromSetting(setting)),
|
||||
));
|
||||
},
|
||||
icon: Icon(Icons.edit, color: primaryColor))
|
||||
]
|
||||
: [],
|
||||
),
|
||||
// body: ZefyrEditor(
|
||||
// padding: EdgeInsets.all(16),
|
||||
// controller: ZefyrController(_loadDocument(setting)),
|
||||
// focusNode: _focusNode,
|
||||
// ),
|
||||
body: Markdown(
|
||||
shrinkWrap: true,
|
||||
softLineBreak: true,
|
||||
physics: const BouncingScrollPhysics(),
|
||||
data: term.replaceAll("\\n", '\n'),
|
||||
styleSheet: MarkdownStyleSheet.fromTheme(ThemeData(
|
||||
textTheme: TextTheme(
|
||||
bodyMedium: TextStyle(
|
||||
fontSize: isEng ? 15 : 14, color: Colors.black87))))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user