FondleTalk/lib/tools/me/setting_page.dart

258 lines
8.2 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:talk/network/NetworkConfig.dart';
import '../../common/func.dart';
import '../../dialog/cancel_dialog.dart';
import '../home_page.dart';
import 'agreement_page.dart';
import 'me_model.dart';
class SettingPage extends StatefulWidget {
const SettingPage({super.key});
@override
State<SettingPage> createState() => _SettingApgeState();
}
class _SettingApgeState extends State<SettingPage> {
late StreamSubscription subscription;
final MeModel _viewmodel = MeModel();
@override
void initState() {
// TODO: implement initState
super.initState();
subscription = _viewmodel.streamController.stream.listen((newData) async {
String code = newData['code'];
if (code.isNotEmpty) {
switch (code) {
case "logout":
if (newData['data']) {
logout();
}
break;
}
}
});
}
///退出登录 注销账号
logout() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('token', "");
NetworkConfig.userId = "";
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (context) => const HomePage()),
(Route<dynamic> route) => false,
);
}
@override
void dispose() {
// TODO: implement dispose
subscription.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Color(0xFF121213),
appBar: AppBar(
backgroundColor: Color(0xFF121213),
scrolledUnderElevation: 0.0,
title: Text(
'设置',
style: TextStyle(fontSize: 16, color: Colors.white),
),
centerTitle: true,
leading: IconButton(
iconSize: 18,
icon: Icon(Icons.arrow_back_ios_sharp),
color: Colors.white,
onPressed: () {
// 处理返回操作
Navigator.pop(context);
},
),
),
body: Stack(
alignment: Alignment.topCenter,
children: [
Container(
height: size.height,
),
Container(
margin: EdgeInsets.symmetric(horizontal: 16),
padding: EdgeInsets.all(21),
decoration: BoxDecoration(color: Color(0xFF202020), borderRadius: BorderRadius.all(Radius.circular(7))),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.pushNamed(context, '/AboutPage');
},
child: SizedBox(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'关于',
style: TextStyle(fontSize: 13, color: Colors.white),
),
Icon(
Icons.keyboard_arrow_right,
color: Color(0xFF6F6F6F),
),
],
),
),
),
Container(
height: 0.33,
color: Color(0xFF3A3A3A),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AgreementPage(
title: "用户协议",
url: "https://shhuanmeng.com/yonghuxieyi.html",
)),
);
},
child: Container(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'用户协议',
style: TextStyle(fontSize: 13, color: Colors.white),
),
Icon(
Icons.keyboard_arrow_right,
color: Color(0xFF6F6F6F),
),
],
),
),
),
Container(
height: 0.33,
color: Color(0xFF3A3A3A),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AgreementPage(
title: "隐私协议",
url: "https://shhuanmeng.com/yinsixieyi.html",
)),
);
},
child: Container(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'隐私协议',
style: TextStyle(fontSize: 13, color: Colors.white),
),
Icon(
Icons.keyboard_arrow_right,
color: Color(0xFF6F6F6F),
),
],
),
),
),
Container(
height: 0.33,
color: Color(0xFF3A3A3A),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.pushNamed(context, '/TeenageModePage');
},
child: const SizedBox(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'青少年模式',
style: TextStyle(fontSize: 13, color: Colors.white),
),
Icon(
Icons.keyboard_arrow_right,
color: Color(0xFF6F6F6F),
),
],
),
),
),
GestureDetector(
onTap: () async {
logout();
},
child: Container(
width: 221,
height: 37,
alignment: Alignment.center,
margin: EdgeInsets.only(top: 40),
decoration: BoxDecoration(
color: Color(0xFFFF9000),
borderRadius: BorderRadius.all(Radius.circular(7.0)),
),
child: Text(
'退出登录',
style: TextStyle(fontSize: 13, color: Colors.black),
),
),
)
],
),
),
Positioned(
bottom: 10,
child: GestureDetector(
onTap: () {
FunctionUtil.popDialog(context, CancelDialog(
onTap: () {
EasyLoading.show(status: "loading...");
_viewmodel.logout();
},
));
},
child: Text(
'注销账号',
style: TextStyle(fontSize: 10, color: Colors.grey),
),
))
],
),
);
}
}