You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

403 lines
12 KiB

4 years ago
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:huixiang/generated/l10n.dart';
4 years ago
import 'package:huixiang/login/login_page.dart';
4 years ago
import 'package:huixiang/main.dart';
import 'package:huixiang/utils/event_type.dart';
import 'package:huixiang/view_widget/round_button.dart';
4 years ago
import 'package:shared_preferences/shared_preferences.dart';
class SettingPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _SettingPage();
}
}
class _SettingPage extends State<SettingPage> {
4 years ago
String locale = "tw";
4 years ago
@override
void initState() {
super.initState();
setLanguage();
}
setLanguage() async {
SharedPreferences shared = await SharedPreferences.getInstance();
locale = shared.getString('language');
if (mounted) setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
S.of(context).shezhi,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
centerTitle: false,
backgroundColor: Color(0xFFF7F7F7),
elevation: 0,
leading: GestureDetector(
onTap: () {
Navigator.of(context).pop();
},
child: Container(
alignment: Alignment.centerRight,
margin: EdgeInsets.only(left: 10),
padding: EdgeInsets.all(6),
child: Icon(
Icons.arrow_back_ios,
color: Colors.black,
size: 24,
),
),
),
titleSpacing: 2,
leadingWidth: 56,
),
4 years ago
body: Container(
decoration: new BoxDecoration(
4 years ago
border:
Border(bottom: BorderSide(color: Color(0xffF7F7F7), width: 0.0)),
color: Color(0xffF7F7F7),
),
child: Column(
4 years ago
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
height: 24,
),
Container(
margin: EdgeInsets.only(left: 16),
child: Text(
S.of(context).shezhi,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color(0xFF353535),
fontSize: 16,
),
),
),
4 years ago
SizedBox(
height: 16,
),
4 years ago
GestureDetector(
onTap: () {
4 years ago
showCupertinoModalPopup(
4 years ago
context: context,
4 years ago
builder: (contetx) {
return CupertinoActionSheet(
title: Text("更换语言"),
actions: [
CupertinoActionSheetAction(
child: Text('简体中文'),
onPressed: () {
changeLanguage("zh");
},
isDefaultAction: true,
isDestructiveAction: false,
),
CupertinoActionSheetAction(
child: Text('繁体中文'),
onPressed: () {
changeLanguage("tw");
},
isDefaultAction: true,
isDestructiveAction: false,
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () {
Navigator.of(context).pop();
},
child: Text("取消"),
isDestructiveAction: true,
),
);
4 years ago
});
},
child: settingItem(
S.of(context).yuyan,
locale == "zh"
? S.of(context).zhongwenjianti
: S.of(context).fantizhongwen),
),
GestureDetector(
child:
settingItem(S.of(context).quanxian, S.of(context).weikaiqi),
onTap: () {
Navigator.of(context).pushNamed('/router/permission_setting');
},
),
GestureDetector(
child: settingSingleItem(S.of(context).bangzhuyufankui),
onTap: () {
Navigator.of(context).pushNamed('/router/help_feedback_page');
},
),
GestureDetector(
child: settingSingleItem(S.of(context).guanyu),
onTap: () {
Navigator.of(context).pushNamed('/router/about_page');
},
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
4 years ago
mainAxisSize: MainAxisSize.max,
4 years ago
children: [
InkWell(
onTap: () {
4 years ago
logOut();
4 years ago
},
child: Container(
height: 54,
alignment: Alignment.center,
color: Color(0xFF32A060),
child: RoundButton(
text: S.of(context).tuichudenglu,
backgroup: Color(0xFF32A060),
textColor: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
],
),
flex: 1,
)
],
),
),
);
}
4 years ago
// changeEnv(env){
// SharedPreferences.getInstance().then((value) => {
// value.setString("env", env),
// });
// Navigator.of(context).pop();
// }
changeLanguage(language) {
if (language == "zh") {
// 语言 語言
4 years ago
S.load(Locale.fromSubtags(languageCode: 'zh', countryCode: 'CN'));
4 years ago
locale = "zh";
4 years ago
eventBus.fire(EventType(0));
4 years ago
} else {
4 years ago
S.load(Locale.fromSubtags(languageCode: 'zh', countryCode: 'TW'));
4 years ago
locale = "tw";
4 years ago
eventBus.fire(EventType(1));
4 years ago
}
SharedPreferences.getInstance().then((value) => {
4 years ago
value.setString("language", language),
});
4 years ago
setState(() {});
Navigator.of(context).pop();
}
4 years ago
logOut() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
sharedPreferences.clear();
// Navigator.of(context).popUntil(ModalRoute.withName('/router/login'));
4 years ago
Navigator.pushAndRemoveUntil(context, new MaterialPageRoute(
builder: (BuildContext context) {
return LoginPage();
},
), (route) => route == null);
4 years ago
}
Widget settingItem(left, right) {
return Container(
margin: EdgeInsets.fromLTRB(16, 8, 16, 8),
padding: EdgeInsets.fromLTRB(20, 16, 20, 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
]),
child: Row(
children: [
Expanded(
child: Text(
left,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14,
color: Color(0xFF353535),
),
),
flex: 1,
),
Text(
right,
style: TextStyle(fontSize: 12, color: Color(0xFF727272)),
),
SizedBox(
width: 16,
),
Icon(
Icons.keyboard_arrow_right,
size: 20,
),
],
),
);
}
Widget settingSingleItem(right) {
return Container(
margin: EdgeInsets.fromLTRB(16, 8, 16, 8),
padding: EdgeInsets.fromLTRB(20, 16, 20, 16),
decoration: BoxDecoration(
4 years ago
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0,
)
],
),
child: Row(
children: [
Expanded(
4 years ago
child: Text(
right,
4 years ago
style: TextStyle(
4 years ago
fontSize: 14,
4 years ago
color: Color(0xFF353535),
fontWeight: FontWeight.bold,
),
),
),
SizedBox(
width: 16,
),
Icon(
Icons.keyboard_arrow_right,
size: 20,
),
],
),
);
}
List<String> title = [
S.current.dingwei,
S.current.tongzhi,
S.current.xiangji,
"Face ID",
];
List<String> icons = [
"assets/image/icon_permission_location.png",
"assets/image/icon_permission_notices.png",
"assets/image/icon_permission_camera.png",
"assets/image/icon_permission_face_id.png",
];
List<String> contents = [
S.current.weizhitishixinxi,
S.current.tongzhitishixinxi,
S.current.xiangjitishixinxi,
S.current.faceidtishixinxi,
];
Widget buildPermissionItem(title, icon, content) {
return Container(
margin: EdgeInsets.fromLTRB(16, 8, 16, 8),
padding: EdgeInsets.fromLTRB(20, 16, 20, 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 3),
blurRadius: 14,
spreadRadius: 0)
]),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Column(
children: [
Row(
children: [
Text(
title,
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 8,
),
Image.asset(
icon,
width: 22,
height: 22,
)
],
),
SizedBox(
height: 8,
),
Text(
content,
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: TextStyle(
color: Color(0xFF353535),
fontSize: 12,
),
),
],
),
),
SizedBox(
width: 32,
),
Row(
children: [
Text(
S.of(context).weikaiqi,
style: TextStyle(
color: Color(0xFF32A060),
fontSize: 12,
),
),
Icon(
Icons.keyboard_arrow_right,
size: 16,
color: Color(0xFF32A060),
)
],
),
],
),
);
}
}