add structure
This commit is contained in:
151
lib/pages/term.dart
Normal file
151
lib/pages/term.dart
Normal file
@@ -0,0 +1,151 @@
|
||||
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);
|
||||
|
||||
bool isOwnerAndAbove =
|
||||
mainModel.user != null && mainModel.user.isOwnerAndAbove();
|
||||
bool hasAdmin = mainModel.user != null && mainModel.user.hasAdmin();
|
||||
|
||||
bool aggreed = mainModel.user.agreeTerms;
|
||||
|
||||
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(
|
||||
automaticallyImplyLeading: !widget.agreePage,
|
||||
title: LocalText(context, 'term.title',
|
||||
color: Colors.white, fontSize: 20),
|
||||
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(
|
||||
data: ZefyrThemeData().copyWith(
|
||||
),
|
||||
child: ZefyrScaffold(
|
||||
child: ZefyrEditor(
|
||||
mode: ZefyrMode.view,
|
||||
padding: EdgeInsets.all(16),
|
||||
controller: _controller,
|
||||
focusNode: _focusNode,
|
||||
),
|
||||
))),
|
||||
)),
|
||||
!aggreed ? agreeBtn : Container(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_agree() async {
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
try {
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
await mainModel.agreeTerms();
|
||||
if (widget.agreePage) {
|
||||
Future.delayed(const Duration(milliseconds: 3000), () {
|
||||
Navigator.pop(context);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user