import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import 'package:makemoney/api/user_api.dart';
|
import 'package:makemoney/utils/config_util.dart';
|
import 'package:package_info/package_info.dart';
|
|
import '../../ui/common/browser.dart';
|
import '../../ui/widget/nav.dart';
|
import '../../utils/cache_util.dart';
|
import '../../utils/pageutils.dart';
|
import '../../utils/setting_util.dart';
|
import '../../utils/share_preference.dart';
|
import '../../utils/string_util.dart';
|
import '../../utils/ui_constant.dart';
|
import '../../utils/ui_utils.dart';
|
import '../../utils/user_util.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 = true;
|
bool content = true;
|
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) {
|
setState(() {
|
ad = value!;
|
});
|
});
|
|
SettingUtil.isEnableRecommendContent().then((value) {
|
setState(() {
|
content = 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 {
|
Map<String, dynamic>? map = await UserApiUtil.logout(context);
|
if (map == null) {
|
return;
|
}
|
if (map["code"] == 0) {
|
UserUtil.logout().then((value) {
|
setState(() {
|
login = false;
|
});
|
ToastUtil.toast("退出成功", context);
|
// popPage(context);
|
});
|
} else {
|
ToastUtil.toast(map["msg"], context);
|
}
|
}
|
|
@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: 1,
|
checked: content,
|
changed: (bool value) {
|
SettingUtil.setRecommendContent(value).then((value1) {
|
setState(() {
|
content = 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: () {
|
showCupertinoDialog(
|
context: context,
|
builder: (context) {
|
return AlertDialog(
|
title: const Text("是否清楚缓存"),
|
actions: <Widget>[
|
TextButton(
|
child: const Text('取消'),
|
onPressed: () {
|
popPage(context);
|
},
|
),
|
TextButton(
|
child: const Text('确定'),
|
onPressed: () {
|
CacheUtil.clear().then((value) {
|
ToastUtil.toast("缓存清除成功", context);
|
_getCacheSize();
|
});
|
popPage(context);
|
},
|
),
|
],
|
);
|
});
|
}),
|
getCommonItemView(
|
title: "检查更新",
|
content: "版本号:$version",
|
onClick: () {
|
ToastUtil.toast("已经是最新版本", context);
|
}),
|
// 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,
|
)))
|
])),
|
);
|
}
|
}
|