2020-05-29 07:45:27 +06:30
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:fcs/model/main_model.dart';
|
|
|
|
|
import 'package:fcs/pages/term_edit.dart';
|
|
|
|
|
import 'package:fcs/pages/util.dart';
|
|
|
|
|
import 'package:fcs/widget/local_text.dart';
|
|
|
|
|
import 'package:fcs/widget/progress.dart';
|
|
|
|
|
import 'package:zefyr/zefyr.dart';
|
|
|
|
|
|
|
|
|
|
import '../theme/theme.dart';
|
|
|
|
|
|
|
|
|
|
typedef void ProfileCallback();
|
|
|
|
|
|
|
|
|
|
class Term extends StatefulWidget {
|
|
|
|
|
final bool agreePage;
|
|
|
|
|
|
|
|
|
|
const Term({Key key, this.agreePage = false}) : super(key: key);
|
|
|
|
|
@override
|
|
|
|
|
_TermState createState() => _TermState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _TermState extends State<Term> {
|
|
|
|
|
ZefyrController _controller;
|
|
|
|
|
FocusNode _focusNode;
|
|
|
|
|
NotusDocument document = new NotusDocument();
|
|
|
|
|
bool isLoading = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_controller = ZefyrController(_loadDocument());
|
|
|
|
|
_focusNode = FocusNode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NotusDocument _loadDocument() {
|
|
|
|
|
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
|
|
|
|
String term = mainModel.setting.terms;
|
|
|
|
|
|
|
|
|
|
NotusDocument doc;
|
|
|
|
|
try {
|
|
|
|
|
doc = NotusDocument.fromJson(jsonDecode(term));
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
if (doc == null) {
|
|
|
|
|
doc = NotusDocument();
|
|
|
|
|
}
|
|
|
|
|
return doc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
MainModel mainModel = Provider.of<MainModel>(context);
|
2020-06-01 14:42:42 +06:30
|
|
|
print("controller terms => ${_controller.document}");
|
2020-05-29 07:45:27 +06:30
|
|
|
|
|
|
|
|
bool isOwnerAndAbove =
|
|
|
|
|
mainModel.user != null && mainModel.user.isOwnerAndAbove();
|
|
|
|
|
bool hasAdmin = mainModel.user != null && mainModel.user.hasAdmin();
|
|
|
|
|
|
2020-06-01 14:42:42 +06:30
|
|
|
// bool aggreed = mainModel.user.agreeTerms;
|
|
|
|
|
bool aggreed = true;
|
2020-05-29 07:45:27 +06:30
|
|
|
|
|
|
|
|
final agreeBtn = Padding(
|
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 10.0),
|
|
|
|
|
child: Card(
|
|
|
|
|
elevation: 10,
|
|
|
|
|
child: Container(
|
|
|
|
|
height: 45.0,
|
|
|
|
|
child: ButtonTheme(
|
|
|
|
|
minWidth: 900.0,
|
|
|
|
|
height: 100.0,
|
|
|
|
|
child: FlatButton.icon(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
showConfirmDialog(context, "term.iagree", () async {
|
|
|
|
|
_agree();
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
label: LocalText(context, "term.agree_btn"),
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.check,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
2020-06-01 14:42:42 +06:30
|
|
|
centerTitle: true,
|
2020-05-29 07:45:27 +06:30
|
|
|
automaticallyImplyLeading: !widget.agreePage,
|
2020-06-01 14:42:42 +06:30
|
|
|
title: LocalText(context, 'term', color: Colors.white, fontSize: 20),
|
2020-05-29 07:45:27 +06:30
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
actions: <Widget>[
|
|
|
|
|
isOwnerAndAbove || hasAdmin
|
|
|
|
|
? IconButton(
|
|
|
|
|
icon: Icon(Icons.edit),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (context) => TermEdit()),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
: Container()
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: Card(
|
|
|
|
|
child: ZefyrTheme(
|
2020-06-01 14:42:42 +06:30
|
|
|
data: ZefyrThemeData().copyWith(),
|
2020-05-29 07:45:27 +06:30
|
|
|
child: ZefyrScaffold(
|
|
|
|
|
child: ZefyrEditor(
|
|
|
|
|
mode: ZefyrMode.view,
|
|
|
|
|
padding: EdgeInsets.all(16),
|
|
|
|
|
controller: _controller,
|
|
|
|
|
focusNode: _focusNode,
|
|
|
|
|
),
|
|
|
|
|
))),
|
|
|
|
|
)),
|
|
|
|
|
!aggreed ? agreeBtn : Container(),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_agree() async {
|
|
|
|
|
setState(() {
|
|
|
|
|
isLoading = true;
|
|
|
|
|
});
|
|
|
|
|
try {
|
2020-06-01 14:42:42 +06:30
|
|
|
// MainModel mainModel = Provider.of<MainModel>(context);
|
|
|
|
|
// await mainModel.agreeTerms();
|
|
|
|
|
// if (widget.agreePage) {
|
|
|
|
|
// Future.delayed(const Duration(milliseconds: 3000), () {
|
|
|
|
|
// Navigator.pop(context);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
2020-05-29 07:45:27 +06:30
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
setState(() {
|
|
|
|
|
isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|