Skip to content

Commit

Permalink
自动跟随系统暗黑模式
Browse files Browse the repository at this point in the history
升级到0.1.7
  • Loading branch information
Rocky.Zhang committed Sep 23, 2019
1 parent d976ef6 commit 807a0f9
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 124 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

# 最近更新

## V0.1.7 `2019-09-23`

- DarkMode自动跟随系统设置
- App更新UI调整
- 适配Dio3.0版本
- pull_to_refresh更新:加入国际化


## V0.1.6 `2019-09-20`

- 修复收藏列表进入详情时,页面报错的bug
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Language: [English](https://github.com/phoenixsky/fun_android_flutter/blob/maste
# 下载地址:
* Android:
* [国内云](http://app.cdn.meetingplus.cn/FunAndroid_0.1.6.apk) | [Github DownLoad](https://github.com/phoenixsky/fun_android_flutter/releases)
* [国内云](http://app.cdn.meetingplus.cn/FunAndroid_0.1.7.apk) | [Github DownLoad](https://github.com/phoenixsky/fun_android_flutter/releases)

![二维码](https://qr.api.cli.im/qr?data=http%3A%2F%2Fqr61.cn%2Fodempq%2FquS5fYM&level=H&transparent=false&bgcolor=%23ffffff&forecolor=%23000000&blockpixel=12&marginblock=2&logourl=http%3A%2F%2Falicliimg.clewm.net%2F020%2F802%2F5802020%2F1566638421597ff5250edab885fcb669e8344a12f03ea1566638376.png&size=260&kid=bizcliim&time=1568947308&key=1ef7092d2d39ddcb84bdb8460fe11e7d)
![二维码](https://qr.api.cli.im/qr?data=http%3A%2F%2Fqr61.cn%2Fodempq%2FquS5fYM&level=H&transparent=false&bgcolor=%23ffffff&forecolor=%23000000&blockpixel=12&marginblock=2&logourl=http%3A%2F%2Falicliimg.clewm.net%2F020%2F802%2F5802020%2F1566638421597ff5250edab885fcb669e8344a12f03ea1566638376.png&size=260&kid=cliim&time=1569234435&key=0636728dfe3f111dc7074c2b44a1d8d4)

* iOS:

Expand Down Expand Up @@ -53,6 +53,13 @@ Language: [English](https://github.com/phoenixsky/fun_android_flutter/blob/maste

# 更新

## V0.1.7 `2019-09-23`

- DarkMode自动跟随系统设置
- App更新组件调整
- 适配Dio3.0版本
- pull_to_refresh更新:加入国际化

## V0.1.6 `2019-09-20`

- 修复收藏列表进入详情时,页面报错的bug
Expand Down
17 changes: 13 additions & 4 deletions lib/generated/i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ class S implements WidgetsLocalizations {
String get appUpdateActionInstallApk => "Install";
String get appUpdateActionUpdate => "Update";
String get appUpdateCheckUpdate => "Check Update";
String get appUpdateDownloading => "downloading...";
String get appUpdateDoubleBackTips => "Press back again, cancel download";
String get appUpdateDownloadCanceled => "Download canceled";
String get appUpdateDownloadFailed => "Download failed";
String get appUpdateDownloading => "Downloading...";
String get appUpdateLeastVersion => "Least version now ";
String get appUpdateReDownloadContent => "It has been detected that it has been downloaded, whether it is installed";
String get appUpdateReDownloadContent => "It has been detected that it has been downloaded, whether it is installed?";
String get appUpdateUpdate => "Version Update";
String get article_tag_top => "Top";
String get autoBySystem => "Auto";
Expand Down Expand Up @@ -142,13 +145,17 @@ class $zh_CN extends S {
@override
String get viewStateButtonRefresh => "刷新一下";
@override
String get appUpdateDoubleBackTips => "再次点击返回键,取消下载";
@override
String get loadFailed => "加载失败,请稍后重试";
@override
String get refreshTwoLevel => "欢迎光临,我的空中楼阁";
@override
String get article_tag_top => "置顶";
@override
String get appUpdateReDownloadContent => "检测到本地已下载过该版本,是否直接安装";
String get appUpdateDownloadFailed => "下载失败";
@override
String get appUpdateReDownloadContent => "检测到本地已下载过该版本,是否直接安装?";
@override
String get noAccount => "还没账号? ";
@override
Expand Down Expand Up @@ -212,6 +219,8 @@ class $zh_CN extends S {
@override
String get userName => "用户名";
@override
String get appUpdateDownloadCanceled => "下载已取消";
@override
String get tabHome => "首页";
@override
String get tabProject => "项目";
Expand All @@ -230,7 +239,7 @@ class $zh_CN extends S {
@override
String get searchHistory => "历史搜索";
@override
String appUpdateFoundNewVersion(String version) => "发现新版本$version,是否更新";
String appUpdateFoundNewVersion(String version) => "发现新版本$version,是否更新?";
}

class GeneratedLocalizationsDelegate extends LocalizationsDelegate<S> {
Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class App extends StatelessWidget {
hideFooterWhenNotFull: true, //列表数据不满一页,不触发加载更多
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: themeModel.themeData,
darkTheme: themeModel.darkTheme,
theme: themeModel.themeData(),
darkTheme: themeModel.themeData(platformDarkMode:true),
locale: localeModel.locale,
localizationsDelegates: const [
S.delegate,
Expand Down
26 changes: 17 additions & 9 deletions lib/ui/page/tab/user_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:fun_android/generated/i18n.dart';
import 'package:fun_android/ui/page/change_log_page.dart';
import 'package:fun_android/ui/widget/app_bar.dart';
import 'package:fun_android/view_model/coin_model.dart';
import 'package:oktoast/oktoast.dart';
import 'package:provider/provider.dart';
import 'package:fun_android/config/resource_mananger.dart';
import 'package:fun_android/config/router_manger.dart';
Expand Down Expand Up @@ -177,26 +178,22 @@ class UserListWidget extends StatelessWidget {
ListTile(
title: Text(S.of(context).darkMode),
onTap: () {
Provider.of<ThemeModel>(context).switchTheme(
brightness: Theme.of(context).brightness == Brightness.light
? Brightness.dark
: Brightness.light);
switchDarkMode(context);
},
leading: Transform.rotate(
angle: -pi,
child: Icon(
Theme.of(context).brightness == Brightness.light
? Icons.brightness_2
: Icons.brightness_5,
? Icons.brightness_5
: Icons.brightness_2,
color: iconColor,
),
),
trailing: CupertinoSwitch(
activeColor: Theme.of(context).accentColor,
value: Theme.of(context).brightness == Brightness.dark,
onChanged: (value) {
Provider.of<ThemeModel>(context).switchTheme(
brightness: value ? Brightness.dark : Brightness.light);
switchDarkMode(context);
}),
),
SettingThemeWidget(),
Expand Down Expand Up @@ -235,6 +232,17 @@ class UserListWidget extends StatelessWidget {
),
);
}

void switchDarkMode(BuildContext context) {
if (MediaQuery.of(context).platformBrightness ==
Brightness.dark) {
showToast("检测到系统为暗黑模式,已为你自动切换",position: ToastPosition.bottom);
} else {
Provider.of<ThemeModel>(context).switchTheme(
userDarkMode:
Theme.of(context).brightness == Brightness.light);
}
}
}

class SettingThemeWidget extends StatelessWidget {
Expand Down Expand Up @@ -262,7 +270,7 @@ class SettingThemeWidget extends StatelessWidget {
onTap: () {
var model = Provider.of<ThemeModel>(context);
var brightness = Theme.of(context).brightness;
model.switchTheme(brightness: brightness, color: color);
model.switchTheme(color: color);
},
child: Container(
width: 40,
Expand Down
150 changes: 77 additions & 73 deletions lib/ui/widget/app_update.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:path_provider/path_provider.dart';

import 'button_progress_indicator.dart';


class AppUpdateButton extends StatelessWidget {
Widget build(BuildContext context) {
return ProviderWidget<AppUpdateModel>(
Expand All @@ -26,14 +25,15 @@ class AppUpdateButton extends StatelessWidget {
onPressed: model.busy
? null
: () async {
String url = await model.checkUpdate();
if (url?.isNotEmpty ?? false) {
bool result = await showUpdateAlertDialog(context,url.split('/').last);
if (result == true) downloadApp(context, url);
} else {
showToast(S.of(context).appUpdateLeastVersion);
}
},
String url = await model.checkUpdate();
if (url?.isNotEmpty ?? false) {
bool result =
await showUpdateAlertDialog(context, url.split('/').last);
if (result == true) downloadApp(context, url);
} else {
showToast(S.of(context).appUpdateLeastVersion);
}
},
),
);
}
Expand All @@ -55,25 +55,24 @@ showUpdateAlertDialog(context, version) async {
return await showDialog(
context: context,
builder: (context) => AlertDialog(
content: Text(S.of(context).appUpdateFoundNewVersion(version)),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: new Text(
S.of(context).actionCancel,
style: TextStyle(color: Colors.black.withOpacity(0.5)),
),
),
FlatButton(
onPressed: () async {
Navigator.of(context).pop(true);
},
child: new Text(S.of(context).appUpdateActionUpdate),
),
],
));
content: Text(S.of(context).appUpdateFoundNewVersion(version)),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: new Text(
S.of(context).actionCancel
),
),
FlatButton(
onPressed: () async {
Navigator.of(context).pop(true);
},
child: new Text(S.of(context).appUpdateActionUpdate),
),
],
));
}

Future downloadApp(BuildContext context, String url) async {
Expand All @@ -87,7 +86,7 @@ Future downloadApp(BuildContext context, String url) async {
OpenFile.open(apkPath);
}
} else {
var reDownload = await showReDownloadDialog(context);
var reDownload = await showReDownloadAlertDialog(context);
//因为点击android的返回键,关闭dialog时的返回值为null
if (reDownload != null) {
if (reDownload) {
Expand All @@ -104,8 +103,9 @@ Future downloadApp(BuildContext context, String url) async {
}

showDownloadDialog(context, url, path) async {
CancelToken cancelToken = CancelToken();
DateTime lastBackPressed;
CancelToken cancelToken = CancelToken();
bool downloading = false;
return await showCupertinoDialog(
context: context,
builder: (context) {
Expand All @@ -116,26 +116,31 @@ showDownloadDialog(context, url, path) async {
Duration(seconds: 1)) {
//两次点击间隔超过1秒则重新计时
lastBackPressed = DateTime.now();
showToast('再次点击返回键,取消下载', position: ToastPosition.bottom);
showToast(S.of(context).appUpdateDoubleBackTips, position: ToastPosition.bottom);
return false;
}
cancelToken.cancel();
showToast('下载已取消', position: ToastPosition.bottom);
showToast(S.of(context).appUpdateDownloadCanceled, position: ToastPosition.bottom);
return true;
},
child: CupertinoAlertDialog(
title: Text('正在下载'),
title: Text(S.of(context).appUpdateDownloading),
content: Builder(
builder: (context) {
debugPrint('Downloader Builder');
ValueNotifier notifier = ValueNotifier(0.0);
Dio().download(url, path, cancelToken: cancelToken,
onReceiveProgress: (progress, total) {
debugPrint('value--${progress / total}');
notifier.value = progress / total;
if (notifier.value == 1) {
Navigator.pop(context, true);
}
});
if (!downloading) {
downloading = true;
Dio().download(url, path, cancelToken: cancelToken,
onReceiveProgress: (progress, total) {
debugPrint('value--${progress / total}');
notifier.value = progress / total;
}).then((Response response) {
Navigator.pop(context, true);
}).catchError((onError){
showToast(S.of(context).appUpdateDownloadFailed);
});
}
return ValueListenableBuilder(
valueListenable: notifier,
builder: (context, value, child) {
Expand All @@ -154,39 +159,38 @@ showDownloadDialog(context, url, path) async {
});
}

showReDownloadDialog(context) async {

showReDownloadAlertDialog(context) async {
return await showDialog(
context: context,
builder: (context) => AlertDialog(
content: Text(S.of(context).appUpdateReDownloadContent),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
S.of(context).actionCancel,
style: TextStyle(color: Colors.black.withOpacity(0.5)),
),
),
SizedBox(
width: 20,
),
FlatButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: Text(
S.of(context).appUpdateActionDownloadAgain,
style: TextStyle(color: Colors.black),
),
),
FlatButton(
onPressed: () async {
Navigator.of(context).pop(false);
},
child: Text(S.of(context).appUpdateActionInstallApk),
),
],
));
content: Text(S.of(context).appUpdateReDownloadContent),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
S.of(context).actionCancel,
),
),
SizedBox(
width: 20,
),
FlatButton(
onPressed: () {
Navigator.of(context).pop(true);
},
child: Text(
S.of(context).appUpdateActionDownloadAgain,
),
),
FlatButton(
onPressed: () async {
Navigator.of(context).pop(false);
},
child: Text(S.of(context).appUpdateActionInstallApk),
),
],
));
}
Loading

0 comments on commit 807a0f9

Please sign in to comment.