370 lines
12 KiB
Dart
370 lines
12 KiB
Dart
|
||
import 'dart:async';
|
||
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
import 'package:shared_preferences/shared_preferences.dart';
|
||
|
||
import '../../common/Global.dart';
|
||
import '../../common/func.dart';
|
||
import '../../generated/l10n.dart';
|
||
import '../../network/NetworkConfig.dart';
|
||
import '../start_model.dart';
|
||
import '../web/CommonlyWebPage.dart';
|
||
|
||
///设置
|
||
class SettingPage extends StatefulWidget {
|
||
const SettingPage({Key? key}) : super(key: key);
|
||
|
||
@override
|
||
State<SettingPage> createState() => _SettingPageState();
|
||
}
|
||
|
||
class _SettingPageState extends State<SettingPage> {
|
||
final StartModel _viewModel = StartModel();
|
||
StreamSubscription? subscription;
|
||
|
||
@override
|
||
void initState() {
|
||
// TODO: implement initState
|
||
super.initState();
|
||
subscription = _viewModel.streamController.stream.listen((newData) {
|
||
String code = newData['code'];
|
||
if (code.isNotEmpty) {
|
||
EasyLoading.dismiss();
|
||
if (code == "getAppConfig") {
|
||
Navigator.of(context).pushNamedAndRemoveUntil('/HomePage', ModalRoute.withName('/'));
|
||
} else if (code == "-1") {
|
||
Navigator.of(context).pushNamedAndRemoveUntil('/HomePage', ModalRoute.withName('/'));
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
// TODO: implement dispose
|
||
super.dispose();
|
||
subscription?.cancel();
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final size = MediaQuery.of(context).size;
|
||
|
||
return Scaffold(
|
||
backgroundColor: Colors.white,
|
||
appBar: AppBar(
|
||
backgroundColor: Colors.white,
|
||
elevation: 1,
|
||
title: Row(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Container(
|
||
margin: const EdgeInsets.only(right: 10),
|
||
child: const Image(
|
||
width: 23,
|
||
height: 23,
|
||
image: AssetImage('assets/images/ic_title.png'),
|
||
),
|
||
),
|
||
Text(
|
||
S.of(context).Settings,
|
||
style: const TextStyle(color: Colors.black, fontSize: 20),
|
||
),
|
||
],
|
||
),
|
||
leading: IconButton(
|
||
icon: const ImageIcon(AssetImage('assets/images/ic_return.png')),
|
||
color: Colors.black,
|
||
onPressed: () {
|
||
Navigator.pop(context);
|
||
}),
|
||
centerTitle: true,
|
||
),
|
||
body: Column(
|
||
children: [
|
||
///语言切换
|
||
_ButtonSw(),
|
||
|
||
///反馈
|
||
GestureDetector(
|
||
behavior: HitTestBehavior.opaque,
|
||
onTap: () {
|
||
Navigator.pushNamed(context, "/FeedbackPage");
|
||
},
|
||
child: SizedBox(
|
||
height: 50,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Positioned(left: 15, child: Text(S.of(context).Feedback)),
|
||
const Positioned(
|
||
right: 15,
|
||
child: Image(
|
||
width: 7,
|
||
height: 12,
|
||
image: AssetImage('assets/images/ic_jump.png'),
|
||
))
|
||
],
|
||
),
|
||
),
|
||
),
|
||
|
||
///隐私协议
|
||
GestureDetector(
|
||
behavior: HitTestBehavior.opaque,
|
||
onTap: () {
|
||
Navigator.push(
|
||
context,
|
||
MaterialPageRoute(
|
||
//导航打开新视图
|
||
builder: (context) => CommonlyWebPage(
|
||
url: NetworkConfig.Language == "zh"
|
||
? "https://appfiles.hissai.com/hissai/PrivacyPolicy.html"
|
||
: "https://appfiles.hissai.com/hissai/PrivacyPolicy_EN.html",
|
||
title: S.of(context).Privacy_Policy,
|
||
) //打开第二个页面,并传值,传递值的名称是model
|
||
));
|
||
},
|
||
child: SizedBox(
|
||
height: 50,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Positioned(left: 15, child: Text(S.of(context).Privacy_Policy)),
|
||
const Positioned(
|
||
right: 15,
|
||
child: Image(
|
||
width: 7,
|
||
height: 12,
|
||
image: AssetImage('assets/images/ic_jump.png'),
|
||
))
|
||
],
|
||
),
|
||
),
|
||
),
|
||
|
||
///用户协议
|
||
GestureDetector(
|
||
behavior: HitTestBehavior.opaque,
|
||
onTap: () {
|
||
Navigator.push(
|
||
context,
|
||
MaterialPageRoute(
|
||
//导航打开新视图
|
||
builder: (context) => CommonlyWebPage(
|
||
url: NetworkConfig.Language == "zh"
|
||
? "https://appfiles.hissai.com/hissai/UserAgreement.html"
|
||
: "https://appfiles.hissai.com/hissai/UserAgreement_EN.html",
|
||
title: S.of(context).User_Agreement,
|
||
) //打开第二个页面,并传值,传递值的名称是model
|
||
));
|
||
},
|
||
child: SizedBox(
|
||
height: 50,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Positioned(left: 15, child: Text(S.of(context).User_Agreement)),
|
||
const Positioned(
|
||
right: 15,
|
||
child: Image(
|
||
width: 7,
|
||
height: 12,
|
||
image: AssetImage('assets/images/ic_jump.png'),
|
||
))
|
||
],
|
||
),
|
||
),
|
||
),
|
||
|
||
///退出登录
|
||
GestureDetector(
|
||
behavior: HitTestBehavior.opaque,
|
||
onTap: () {
|
||
cleanUser();
|
||
},
|
||
child: SizedBox(
|
||
height: 50,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Positioned(left: 15, child: Text(S.of(context).Exit_login)),
|
||
const Positioned(
|
||
right: 15,
|
||
child: Image(
|
||
width: 7,
|
||
height: 12,
|
||
image: AssetImage('assets/images/ic_jump.png'),
|
||
))
|
||
],
|
||
),
|
||
),
|
||
),
|
||
|
||
///关于
|
||
GestureDetector(
|
||
behavior: HitTestBehavior.opaque,
|
||
onTap: () {
|
||
Navigator.pushNamed(context, "/AboutPage");
|
||
},
|
||
child: SizedBox(
|
||
height: 50,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Positioned(left: 15, child: Text(S.of(context).About)),
|
||
const Positioned(
|
||
right: 15,
|
||
child: Image(
|
||
width: 7,
|
||
height: 12,
|
||
image: AssetImage('assets/images/ic_jump.png'),
|
||
))
|
||
],
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
///语言切换
|
||
_ButtonSw() {
|
||
return GestureDetector(
|
||
onTap: () {
|
||
FunctionUtil.bottomSheetDialog(
|
||
context,
|
||
Container(
|
||
decoration: const BoxDecoration(
|
||
color: Colors.white, borderRadius: BorderRadius.only(topLeft: Radius.circular(10.0), topRight: Radius.circular(10.0))),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
GestureDetector(
|
||
onTap: () {
|
||
setLanguageSw(1);
|
||
},
|
||
child: Container(
|
||
alignment: Alignment.center,
|
||
height: 50,
|
||
width: double.infinity,
|
||
color: Colors.white,
|
||
child: Text(
|
||
"English(United States)",
|
||
style: TextStyle(color: NetworkConfig.Language == '' || NetworkConfig.Language == 'en' ? Colors.red : Colors.black),
|
||
),
|
||
),
|
||
),
|
||
_Line(),
|
||
GestureDetector(
|
||
onTap: () {
|
||
//Navigator.pop(context);
|
||
setLanguageSw(2);
|
||
},
|
||
child: Container(
|
||
alignment: Alignment.center,
|
||
height: 50,
|
||
width: double.infinity,
|
||
color: Colors.white,
|
||
child: Text(
|
||
"中文简体(中国)",
|
||
style: TextStyle(color: NetworkConfig.Language == 'zh' ? Colors.red : Colors.black),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
));
|
||
},
|
||
child: Container(
|
||
margin: const EdgeInsets.only(top: 0, left: 0, right: 0),
|
||
color: Colors.white,
|
||
height: 50,
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: <Widget>[
|
||
Container(
|
||
margin: const EdgeInsets.only(top: 0, left: 15, bottom: 0, right: 15),
|
||
child: Text(
|
||
S.of(context).Language_switching,
|
||
style: const TextStyle(
|
||
color: Colors.black,
|
||
),
|
||
)),
|
||
Container(
|
||
alignment: Alignment.centerRight,
|
||
margin: const EdgeInsets.only(right: 10, left: 10),
|
||
child: Text(
|
||
NetworkConfig.Language == 'zh' ? "中文简体" : "English",
|
||
overflow: TextOverflow.ellipsis,
|
||
style: const TextStyle(
|
||
color: Colors.black,
|
||
fontSize: 14,
|
||
fontWeight: FontWeight.w600,
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
));
|
||
}
|
||
|
||
setLanguageSw(index) async {
|
||
var lc;
|
||
if (index == 1) {
|
||
lc = "en";
|
||
} else if (index == 2) {
|
||
lc = "zh";
|
||
} else if (index == 3) {
|
||
lc = "ja";
|
||
}
|
||
S.load(Locale.fromSubtags(languageCode: lc));
|
||
NetworkConfig.Language = lc;
|
||
Map<String, String> map = {"languageCode": NetworkConfig.Language};
|
||
invokeNativeMethod("LanguageSw", map);
|
||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||
prefs.setString("LanguageSw", NetworkConfig.Language);
|
||
|
||
EasyLoading.show(status: 'loading...', maskType: EasyLoadingMaskType.black);
|
||
|
||
_viewModel.getAppConfig();
|
||
}
|
||
|
||
_Line() {
|
||
return DecoratedBox(
|
||
//线
|
||
decoration: BoxDecoration(border: Border.all(color: const Color(0x4cCFCFCF), width: 1.0)),
|
||
child: const SizedBox(
|
||
height: 1,
|
||
width: double.infinity,
|
||
),
|
||
);
|
||
}
|
||
|
||
//清除用户数据 退出登录
|
||
cleanUser() async {
|
||
NetworkConfig.userId = "";
|
||
NetworkConfig.token = "";
|
||
NetworkConfig.userToken = "";
|
||
NetworkConfig.allCurrency = "0";
|
||
Navigator.of(context).pushNamedAndRemoveUntil('/HomePage', ModalRoute.withName('/'));
|
||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||
prefs.setString("UserBean", "");
|
||
|
||
Map<String, String> map = {"exitLogin": "exitLogin"};
|
||
invokeNativeMethod("exitLogin", map);
|
||
}
|
||
|
||
// 获取原生的值
|
||
invokeNativeMethod(String method, Map<String, dynamic> map) async {
|
||
dynamic args;
|
||
try {
|
||
args = await Global.method.invokeMethod(method, map);
|
||
} on PlatformException catch (e) {}
|
||
}
|
||
}
|