import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import '../../api/http.dart';
|
import '../../ui/common/browser.dart';
|
import '../../ui/widget/dialog.dart';
|
import '../../ui/widget/nav.dart';
|
import '../../utils/cache_util.dart';
|
import '../../utils/config_util.dart';
|
import '../../utils/event_bus_util.dart';
|
import '../../utils/pageutils.dart';
|
import '../../utils/push_util.dart';
|
import '../../utils/setting_util.dart';
|
import '../../utils/string_util.dart';
|
import '../../utils/ui_constant.dart';
|
import '../../utils/ui_utils.dart';
|
import '../../utils/user_util.dart';
|
import 'package:package_info/package_info.dart';
|
|
void main() {
|
runApp(MyApp());
|
}
|
|
class MyApp extends StatelessWidget {
|
// This widget is the root of your application.
|
@override
|
Widget build(BuildContext context) {
|
return MaterialApp(
|
title: '设置',
|
theme: ThemeData(primaryColor: const Color(0xFFF5F5F5)),
|
home: SettingPage(title: ''),
|
);
|
}
|
}
|
|
class SettingPage extends StatefulWidget {
|
SettingPage({Key? key, required this.title}) : super(key: key);
|
|
// This widget is the home page of your application. It is stateful, meaning
|
// that it has a State object (defined below) that contains fields that affect
|
// how it looks.
|
|
// This class is the configuration for the state. It holds the values (in this
|
// case the title) provided by the parent (in this case the App widget) and
|
// used by the build method of the State. Fields in a Widget subclass are
|
// always marked "final".
|
|
final String title;
|
|
@override
|
_SettingPageState createState() => _SettingPageState();
|
}
|
|
class _SettingPageState extends State<SettingPage>
|
with SingleTickerProviderStateMixin {
|
bool msg = false;
|
bool ad = false;
|
bool login = false;
|
|
String cacheSize = "0B";
|
String version = "";
|
|
@override
|
void initState() {
|
super.initState();
|
UserUtil.isLogin().then((value) {
|
setState(() {
|
login = value;
|
});
|
});
|
|
_getCacheSize();
|
_getVersion();
|
|
SettingUtil.isEnablePush().then((value) {
|
setState(() {
|
msg = value;
|
});
|
});
|
|
SettingUtil.isEnableRecommendAd().then((value) {
|
ad = value;
|
});
|
}
|
|
///获取缓存大小
|
void _getCacheSize() async {
|
int byteSize = await CacheUtil.total();
|
String? desc;
|
if (byteSize < 1000) {
|
desc = byteSize.toString() + "KB";
|
} else if (byteSize < 1000 * 1000) {
|
desc = (byteSize / 1000).toStringAsFixed(0) + "KB";
|
} else if (byteSize < 1000 * 1000 * 1000) {
|
desc = (byteSize / (1000 * 1000)).toStringAsFixed(1) + "MB";
|
} else {
|
desc = (byteSize / (1000 * 1000 * 1000)).toStringAsFixed(1) + "GB";
|
}
|
|
setState(() {
|
cacheSize = desc!;
|
});
|
}
|
|
void _getVersion() async {
|
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
setState(() {
|
version = packageInfo.version;
|
});
|
}
|
|
Future logout() async {
|
var uid = await UserUtil.getUid();
|
Map<String, dynamic>? map = await UserApiUtil.logout(context, uid);
|
if (map!["code"] == 0) {
|
UserUtil.logout();
|
setState(() {
|
login = false;
|
});
|
ToastUtil.toast("退出成功");
|
Navigator.of(context).pop();
|
} else {
|
ToastUtil.toast(map["msg"]);
|
}
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
backgroundColor: const Color(0xFFF5F5F5),
|
body: Flex(
|
direction: Axis.vertical,
|
children: [
|
TopNavBar(title: "设置"),
|
getBigItemView(
|
title: "推送免打扰",
|
content: "关闭后,21:00-09:00不接受任何推送",
|
marginTop: 14,
|
marginBottom: 1,
|
checked: msg,
|
changed: (bool value) {
|
SettingUtil.setPush(value).then((value1) {
|
setState(() {
|
msg = value;
|
});
|
});
|
}),
|
getBigItemView(
|
title: "个性化广告推荐",
|
content: "关闭后,广告数量将不变,但内容相关度会降低",
|
marginTop: 0,
|
marginBottom: 16,
|
checked: ad,
|
changed: (bool value) {
|
SettingUtil.setRecommendAd(value).then((value1) {
|
setState(() {
|
ad = value;
|
});
|
});
|
}),
|
getCommonItemView(
|
title: "清理缓存",
|
content: cacheSize,
|
onClick: () {
|
DialogUtil.showDialog(
|
context,
|
NotifyDialog("温馨提示", "是否清楚缓存?", () {}, () {
|
CacheUtil.clear().then((value) {
|
ToastUtil.toast("缓存清除成功");
|
_getCacheSize();
|
});
|
}));
|
}),
|
getCommonItemView(
|
title: "检查更新",
|
content: "版本号:$version",
|
onClick: () {
|
ToastUtil.toast("已经是最新版本");
|
}),
|
getCommonItemView(
|
title: "账户注销",
|
content: "",
|
onClick: () {
|
ConfigUtil.getConfig(ConfigKey.unRegister).then((value) {
|
if (!StringUtil.isNullOrEmpty(value)) {
|
NavigatorUtil.navigateToNextPage(context,
|
BrowserPage(title: "账户注销", url: value!), (data) {});
|
}
|
});
|
}),
|
getCommonItemView(
|
title: "隐私投诉",
|
content: "",
|
onClick: () {
|
ConfigUtil.getConfig(ConfigKey.privacyComplain).then((value) {
|
if (!StringUtil.isNullOrEmpty(value)) {
|
NavigatorUtil.navigateToNextPage(context,
|
BrowserPage(title: "隐私投诉", url: value!), (data) {});
|
}
|
});
|
}),
|
// getCommonItemView(
|
// title: "第三方SDK列表",
|
// content: "",
|
// onClick: () {
|
//
|
// ConfigUtil.getConfig(ConfigKey.sdkList).then((value) {
|
// if (!StringUtil.isNullOrEmpty(value)) {
|
// NavigatorUtil.navigateToNextPage(
|
// context, BrowserPage(title: "第三方SDK列表", url: value!), (data) {});
|
// }
|
// });
|
// }),
|
Expanded(
|
child: Container(),
|
),
|
login
|
? Container(
|
child: Stack(
|
children: [
|
InkWell(
|
onTap: () {
|
print("退出登录");
|
logout();
|
},
|
child: Container(
|
alignment: Alignment.center,
|
height: 48,
|
color: Colors.white,
|
child: const Text(
|
"退出登录",
|
style: TextStyle(
|
color: ColorConstant.theme, fontSize: 16),
|
)))
|
],
|
))
|
: Container(),
|
],
|
));
|
}
|
|
Widget getCommonItemView(
|
{required String title,
|
String content = "",
|
required GestureTapCallback onClick}) {
|
return Container(
|
height: 53,
|
margin: const EdgeInsets.fromLTRB(0, 0, 0, 1),
|
color: Colors.white,
|
child: InkWell(
|
onTap: () {
|
onClick();
|
},
|
child: Container(
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
|
child: Flex(
|
crossAxisAlignment: CrossAxisAlignment.center,
|
direction: Axis.horizontal,
|
children: [
|
Text(
|
title,
|
style:
|
const TextStyle(fontSize: 16, color: Color(0xFF333333)),
|
),
|
Expanded(
|
child: Flex(
|
direction: Axis.horizontal,
|
mainAxisAlignment: MainAxisAlignment.end,
|
children: [
|
Container(
|
child: Text(content,
|
style: const TextStyle(
|
fontSize: 14, color: Color(0xFF959595))),
|
margin: const EdgeInsets.fromLTRB(0, 0, 13.5, 0),
|
),
|
Image.asset(
|
"assets/imgs/common/icon_array_right.png",
|
height: 13.5,
|
)
|
],
|
))
|
],
|
)),
|
),
|
);
|
}
|
|
Widget getBigItemView(
|
{required String title,
|
String content = "",
|
bool checked = false,
|
required ValueChanged<bool> changed,
|
double marginTop = 0,
|
double marginBottom = 0}) {
|
return Container(
|
height: 68,
|
margin: EdgeInsets.fromLTRB(0, marginTop, 0, marginBottom),
|
color: Colors.white,
|
child: Container(
|
padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
|
child: Stack(children: [
|
Flex(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.center,
|
direction: Axis.vertical,
|
children: [
|
Text(
|
title,
|
style: TextStyle(fontSize: 16, color: Color(0xFF333333)),
|
),
|
Container(
|
child: Text(content,
|
style: const TextStyle(
|
fontSize: 9, color: Color(0xFF959595))),
|
margin: const EdgeInsets.fromLTRB(0, 5, 0, 0),
|
)
|
],
|
),
|
Container(),
|
Positioned(
|
right: 0,
|
top: 0,
|
bottom: 0,
|
child: InkWell(
|
onTap: () {
|
changed(!checked);
|
},
|
child: Image.asset(
|
checked
|
? "assets/imgs/common/icon_check_true.png"
|
: "assets/imgs/common/icon_check_false.png",
|
height: 30,
|
width: 60,
|
)))
|
])),
|
);
|
}
|
}
|