|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_screenutil/screenutil.dart';
|
|
|
|
import 'package:one_key/constant/state.dart';
|
|
|
|
import 'package:one_key/models/remark.dart';
|
|
|
|
import 'package:one_key/provider/remark_manager_model.dart';
|
|
|
|
import 'package:one_key/provider/user_model.dart';
|
|
|
|
import 'package:one_key/res/colors.dart';
|
|
|
|
import 'package:one_key/utils/utils.dart';
|
|
|
|
import 'package:one_key/widgets/MyDivider.dart';
|
|
|
|
import 'package:one_key/widgets/h_empty_view.dart';
|
|
|
|
import 'package:one_key/widgets/page_exception.dart';
|
|
...
|
...
|
@@ -30,41 +32,56 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { |
|
|
|
TextEditingController _controller = TextEditingController();
|
|
|
|
FocusNode focusNode = FocusNode();
|
|
|
|
|
|
|
|
int alwaysCount = 0; //常用备注数
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
// TODO: implement initState
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
|
|
|
_getRemarks();
|
|
|
|
_getRemarks(showPageLoading: true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取备注
|
|
|
|
_getRemarks() {
|
|
|
|
_getRemarks({bool showPageLoading = false}) {
|
|
|
|
Map<String, String> params = {
|
|
|
|
"uid": Provider.of<UserModel>(context, listen: false).user.openid
|
|
|
|
};
|
|
|
|
remarkManagerModel.getRemarks(context, params);
|
|
|
|
remarkManagerModel.getRemarks(context, params,
|
|
|
|
showPageLoading: showPageLoading);
|
|
|
|
}
|
|
|
|
|
|
|
|
//添加备注
|
|
|
|
_addRemark() {
|
|
|
|
_addRemark() async {
|
|
|
|
Map<String, String> params = {
|
|
|
|
"uid": Provider.of<UserModel>(context, listen: false).user.openid,
|
|
|
|
"custom": _controller.text
|
|
|
|
};
|
|
|
|
remarkManagerModel.addRemark(context, params);
|
|
|
|
await remarkManagerModel.addRemark(context, params);
|
|
|
|
_getRemarks(showPageLoading: false); //添加完重新获取备注信息
|
|
|
|
}
|
|
|
|
|
|
|
|
//删除备注
|
|
|
|
_delRemark(Remark remark) {
|
|
|
|
//添加常用备注
|
|
|
|
_addCustomRemark(Remark remark) {
|
|
|
|
Map<String, String> params = {
|
|
|
|
"uid": Provider.of<UserModel>(context, listen: false).user.openid,
|
|
|
|
"kid": remark.id,
|
|
|
|
"flag": "custom"
|
|
|
|
};
|
|
|
|
remarkManagerModel.getRemarks(context, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
//取消常用备注
|
|
|
|
_delCustomRemark(Remark remark) {
|
|
|
|
if (remark.id == "-1") return;
|
|
|
|
Map<String, String> params = {
|
|
|
|
"uid": Provider.of<UserModel>(context, listen: false).user.openid,
|
|
|
|
"kid": remark.id,
|
|
|
|
"flag": "often"
|
|
|
|
};
|
|
|
|
remarkManagerModel.delRemark(context, params);
|
|
|
|
remarkManagerModel.getRemarks(context, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
//构建常用备注
|
|
...
|
...
|
@@ -98,24 +115,24 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { |
|
|
|
color: MyColours.color_6AB6B9,
|
|
|
|
),
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
remark.oftenUse = "";
|
|
|
|
});
|
|
|
|
_delRemark(remark);
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
remark.oftenUse = "";
|
|
|
|
});
|
|
|
|
_delCustomRemark(remark);
|
|
|
|
},
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
|
|
|
|
child: Text(
|
|
|
|
"X",
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_ffffff,
|
|
|
|
fontSize: ScreenUtil().setSp(30)),
|
|
|
|
)),
|
|
|
|
)
|
|
|
|
child: Image.asset(
|
|
|
|
"assets/icon_remark_del.png",
|
|
|
|
width: ScreenUtil().setWidth(18),
|
|
|
|
height: ScreenUtil().setWidth(18),
|
|
|
|
),
|
|
|
|
))
|
|
|
|
]),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
alwaysCount = always.length;
|
|
|
|
return always;
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -126,8 +143,13 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { |
|
|
|
alls.add(
|
|
|
|
GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
if (alwaysCount >= 10) {
|
|
|
|
Utils.showToast("最多添加10个常用备注");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setState(() {
|
|
|
|
remark.oftenUse = remark.custom;
|
|
|
|
_addCustomRemark(remark);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Container(
|
|
...
|
...
|
@@ -170,6 +192,7 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { |
|
|
|
? Container(
|
|
|
|
width: ScreenUtil().setWidth(200),
|
|
|
|
height: ScreenUtil().setWidth(50),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(horizontal: ScreenUtil().setWidth(20)),
|
|
|
|
decoration: BoxDecoration(
|
|
...
|
...
|
@@ -178,46 +201,43 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { |
|
|
|
width: ScreenUtil().setWidth(2)),
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(ScreenUtil().setWidth(10))),
|
|
|
|
child: Expanded(
|
|
|
|
child: TextField(
|
|
|
|
controller: _controller,
|
|
|
|
focusNode: focusNode,
|
|
|
|
autofocus: true,
|
|
|
|
textInputAction: TextInputAction.done,
|
|
|
|
textAlignVertical: TextAlignVertical.center,
|
|
|
|
keyboardType: TextInputType.text,
|
|
|
|
maxLength: 10,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: InputBorder.none,
|
|
|
|
),
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_353535,
|
|
|
|
fontSize: ScreenUtil().setSp(30),
|
|
|
|
textBaseline:
|
|
|
|
TextBaseline.alphabetic),
|
|
|
|
onEditingComplete: () {
|
|
|
|
if(_controller.text.isEmpty){
|
|
|
|
setState(() {
|
|
|
|
isAdding=false;
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
child: TextField(
|
|
|
|
controller: _controller,
|
|
|
|
focusNode: focusNode,
|
|
|
|
autofocus: true,
|
|
|
|
textInputAction: TextInputAction.done,
|
|
|
|
textAlignVertical: TextAlignVertical.center,
|
|
|
|
keyboardType: TextInputType.text,
|
|
|
|
decoration: InputDecoration.collapsed(hintText: ""),
|
|
|
|
inputFormatters: [LengthLimitingTextInputFormatter(10)],
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_353535,
|
|
|
|
fontSize: ScreenUtil().setSp(30),
|
|
|
|
textBaseline: TextBaseline.alphabetic),
|
|
|
|
onEditingComplete: () {
|
|
|
|
if (_controller.text.isEmpty) {
|
|
|
|
setState(() {
|
|
|
|
isAdding = false;
|
|
|
|
remarkManagerModel.remarks.add(Remark()
|
|
|
|
..id = "-1"
|
|
|
|
..custom = _controller.text
|
|
|
|
..oftenUse = _controller.text);
|
|
|
|
return;
|
|
|
|
});
|
|
|
|
_addRemark();
|
|
|
|
_controller.clear();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
setState(() {
|
|
|
|
isAdding = false;
|
|
|
|
});
|
|
|
|
_addRemark();
|
|
|
|
_controller.clear();
|
|
|
|
},
|
|
|
|
))
|
|
|
|
: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
if(remarkManagerModel.remarks.length>=20)return;
|
|
|
|
if (remarkManagerModel.remarks.length >= 20) {
|
|
|
|
Utils.showToast("最多添加20个备注");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (alwaysCount >= 10) {
|
|
|
|
Utils.showToast("最多添加10个常用备注");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setState(() {
|
|
|
|
isAdding = true;
|
|
|
|
});
|
|
...
|
...
|
@@ -235,10 +255,10 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { |
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.add,
|
|
|
|
size: ScreenUtil().setWidth(30),
|
|
|
|
color: MyColours.color_999999,
|
|
|
|
Image.asset(
|
|
|
|
"assets/icon_remark_add.png",
|
|
|
|
width: ScreenUtil().setWidth(30),
|
|
|
|
height: ScreenUtil().setWidth(30),
|
|
|
|
),
|
|
|
|
HEmptyView(10),
|
|
|
|
Text(
|
|
...
|
...
|
@@ -276,7 +296,7 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { |
|
|
|
return ExceptionPage(
|
|
|
|
pageState: model.pageState,
|
|
|
|
callback: () {
|
|
|
|
_getRemarks();
|
|
|
|
_getRemarks(showPageLoading: true);
|
|
|
|
},
|
|
|
|
emptyMsg: "暂时没有备注哦",
|
|
|
|
emptyImg: "empty_search",
|
|
...
|
...
|
@@ -310,13 +330,12 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { |
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
vertical: ScreenUtil().setWidth(20)),
|
|
|
|
vertical: ScreenUtil().setWidth(40)),
|
|
|
|
child: Wrap(
|
|
|
|
spacing: ScreenUtil().setWidth(20),
|
|
|
|
runSpacing: ScreenUtil().setWidth(20),
|
|
|
|
children: _buildAlwayItems()),
|
|
|
|
),
|
|
|
|
VEmptyView(20),
|
|
|
|
MyDivider(
|
|
|
|
double.infinity,
|
|
|
|
ScreenUtil().setWidth(2),
|
|
...
|
...
|
@@ -343,7 +362,7 @@ class RemarkManagerPageState extends State<RemarkManagerPage> { |
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
vertical: ScreenUtil().setWidth(20)),
|
|
|
|
vertical: ScreenUtil().setWidth(40)),
|
|
|
|
child: Wrap(
|
|
|
|
spacing: ScreenUtil().setWidth(20),
|
|
|
|
runSpacing: ScreenUtil().setWidth(20),
|
...
|
...
|
|