setting_page.dart
4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:wow_english/common/utils/video_rendering_preference.dart';
import 'package:wow_english/common/widgets/we_app_bar.dart';
import 'package:wow_english/utils/toast_util.dart';
import '../../../route/route.dart';
class SettingPage extends StatefulWidget {
const SettingPage({super.key});
@override
State<StatefulWidget> createState() {
return SettingPageState();
}
}
class SettingPageState extends State<SettingPage> {
String? _version;
String? _buildNum;
bool _usePlatformView = false;
@override
void initState() {
super.initState();
_usePlatformView = VideoRenderingPreference.usesPlatformView;
_retrieveVersionInfo();
}
Future<void> _retrieveVersionInfo() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
setState(() {
_version = packageInfo.version;
_buildNum = packageInfo.buildNumber;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const WEAppBar(
titleText: '设置',
),
body: Container(
color: Colors.white,
padding: EdgeInsets.only(left: 17.w, right: 17.w),
child: SafeArea(
child: Center(
child: ListView(
children: [
34.verticalSpace,
_buildItemWidget('注销账号', onPress: () {
pushNamed(AppRouteName.deleteAccount);
}),
12.verticalSpace,
_buildItemWidget('清除缓存', onPress: () {
EasyLoading.show();
Future.delayed(const Duration(seconds: 1), (){
showToast("清除成功");
EasyLoading.dismiss();
});
}),
12.verticalSpace,
_buildItemWidget('帮助与反馈', onPress: () {
pushNamed(AppRouteName.reBack);
}),
if (defaultTargetPlatform == TargetPlatform.android) ...[
12.verticalSpace,
_buildVideoRenderingSetting(),
],
12.verticalSpace,
_buildItemWidget('Version: $_version Build:$_buildNum',
onPress: () {}),
],
),
),
),
),
);
}
Widget _buildVideoRenderingSetting() {
return Container(
padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 10.h),
decoration: BoxDecoration(
border: Border.all(color: const Color(0xFF140C10), width: 1.5.w),
borderRadius: BorderRadius.circular(15.r),
color: Colors.white,
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'视频兼容模式',
style: TextStyle(
color: const Color(0xFF333333), fontSize: 19.sp),
),
4.verticalSpace,
Text(
_usePlatformView
? 'PlatformView(兼容测试)· 新打开的视频生效'
: 'Texture(默认)· 新打开的视频生效',
style: TextStyle(
color: const Color(0xFF777777), fontSize: 13.sp),
),
],
),
),
Switch.adaptive(
value: _usePlatformView,
onChanged: (value) async {
setState(() => _usePlatformView = value);
await VideoRenderingPreference.setUsesPlatformView(value);
showToast(value ? '已切换为 PlatformView' : '已切换为 Texture');
},
),
],
),
);
}
Widget _buildItemWidget(String text, {VoidCallback? onPress}) {
return OutlinedButton(
onPressed: () => onPress?.call(),
style: ButtonStyle(
side: MaterialStateProperty.all(
BorderSide(color: const Color(0xFF140C10), width: 1.5.w)),
shape: MaterialStateProperty.all(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.r))),
minimumSize: MaterialStateProperty.all(Size(double.infinity, 58.h)),
backgroundColor: MaterialStateProperty.all(Colors.white),
),
child: Text(
text,
style: TextStyle(
//fontWeight: FontWeight.w600,
color: const Color(0xFF333333),
fontSize: 21.sp,
),
),
);
}
}