mirror of
https://github.com/asjqkkkk/flutter-todos.git
synced 2025-08-26 14:06:29 +08:00
用户名自定义完成!
This commit is contained in:
@ -59,7 +59,7 @@ android {
|
||||
release {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig signingConfigs.debug
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -6,7 +6,7 @@ import 'package:path/path.dart' as p;
|
||||
|
||||
|
||||
|
||||
|
||||
//图片缓存管理类,目前没有用到
|
||||
class CustomCacheManager extends BaseCacheManager {
|
||||
static const key = "customCache";
|
||||
|
||||
|
@ -3,6 +3,7 @@ import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:todo_list/utils/size_util.dart';
|
||||
|
||||
//正六边形实现
|
||||
class FloatingBorder extends ShapeBorder {
|
||||
@override
|
||||
// TODO: implement dimensions
|
||||
|
@ -18,6 +18,7 @@ class Keys{
|
||||
static final String currentNetPicUrl = "current_net_pic_url";
|
||||
static final String currentPosition = "currentPosition";
|
||||
static final String enableWeatherShow = "enable_weather_show";
|
||||
static final String currentUserName = "current_user_name";
|
||||
|
||||
|
||||
}
|
@ -180,6 +180,12 @@ class DemoLocalizations {
|
||||
);
|
||||
}
|
||||
|
||||
String get customUserName => Intl.message('Setting your username', name: 'customUserName', desc: '昵称设置',);
|
||||
String get inputUserName => Intl.message('input your username', name: 'inputUserName', desc: '输入你的昵称吧',);
|
||||
String get userNameCantBeNull => Intl.message('username can not be empty', name: 'userNameCantBeNull', desc: '昵称不能为空哦!',);
|
||||
|
||||
|
||||
|
||||
String get pink{
|
||||
return Intl.message(
|
||||
'pink',
|
||||
|
@ -55,6 +55,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"currentIcons" : MessageLookupByLibrary.simpleMessage("Current Icons"),
|
||||
"customIcon" : MessageLookupByLibrary.simpleMessage("Custom Icon"),
|
||||
"customTheme" : MessageLookupByLibrary.simpleMessage("Custom Theme"),
|
||||
"customUserName" : MessageLookupByLibrary.simpleMessage("Setting your username"),
|
||||
"cyan" : MessageLookupByLibrary.simpleMessage("cyan"),
|
||||
"dailyPic" : MessageLookupByLibrary.simpleMessage("Daily wallpaper"),
|
||||
"dark" : MessageLookupByLibrary.simpleMessage("dark"),
|
||||
@ -80,6 +81,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"hours" : m1,
|
||||
"iconSetting" : MessageLookupByLibrary.simpleMessage("Icon Setting"),
|
||||
"inputCurrentCity" : MessageLookupByLibrary.simpleMessage("input your city"),
|
||||
"inputUserName" : MessageLookupByLibrary.simpleMessage("input your username"),
|
||||
"itemNumber" : m2,
|
||||
"languageTitle" : MessageLookupByLibrary.simpleMessage("Change Language"),
|
||||
"loading" : MessageLookupByLibrary.simpleMessage("loading..."),
|
||||
@ -118,6 +120,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"travel" : MessageLookupByLibrary.simpleMessage("Travel"),
|
||||
"tryToSearch" : MessageLookupByLibrary.simpleMessage("Try searching for the title or content"),
|
||||
"unknownDes" : MessageLookupByLibrary.simpleMessage("Unknown permission"),
|
||||
"userNameCantBeNull" : MessageLookupByLibrary.simpleMessage("username can not be empty"),
|
||||
"versionDescription" : MessageLookupByLibrary.simpleMessage("Version Description"),
|
||||
"waitAMoment" : MessageLookupByLibrary.simpleMessage("please wait for a moment..."),
|
||||
"weatherGetWrong" : MessageLookupByLibrary.simpleMessage("failed to get the weather,please try again"),
|
||||
|
@ -55,6 +55,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"currentIcons" : MessageLookupByLibrary.simpleMessage("当前图标"),
|
||||
"customIcon" : MessageLookupByLibrary.simpleMessage("自定义图标"),
|
||||
"customTheme" : MessageLookupByLibrary.simpleMessage("自定义主题"),
|
||||
"customUserName" : MessageLookupByLibrary.simpleMessage("昵称设置"),
|
||||
"cyan" : MessageLookupByLibrary.simpleMessage("蓝天白云"),
|
||||
"dailyPic" : MessageLookupByLibrary.simpleMessage("每日壁纸"),
|
||||
"dark" : MessageLookupByLibrary.simpleMessage("不见五指"),
|
||||
@ -80,6 +81,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"hours" : m1,
|
||||
"iconSetting" : MessageLookupByLibrary.simpleMessage("图标设置"),
|
||||
"inputCurrentCity" : MessageLookupByLibrary.simpleMessage("手动输入你的城市"),
|
||||
"inputUserName" : MessageLookupByLibrary.simpleMessage("输入你的昵称吧"),
|
||||
"itemNumber" : m2,
|
||||
"languageTitle" : MessageLookupByLibrary.simpleMessage("切换语言"),
|
||||
"loading" : MessageLookupByLibrary.simpleMessage("加载中..."),
|
||||
@ -118,6 +120,7 @@ class MessageLookup extends MessageLookupByLibrary {
|
||||
"travel" : MessageLookupByLibrary.simpleMessage("旅行"),
|
||||
"tryToSearch" : MessageLookupByLibrary.simpleMessage("试试搜一下标题、内容吧"),
|
||||
"unknownDes" : MessageLookupByLibrary.simpleMessage("未知权限"),
|
||||
"userNameCantBeNull" : MessageLookupByLibrary.simpleMessage("昵称不能为空哦!"),
|
||||
"versionDescription" : MessageLookupByLibrary.simpleMessage("版本描述"),
|
||||
"waitAMoment" : MessageLookupByLibrary.simpleMessage("请稍后..."),
|
||||
"weatherGetWrong" : MessageLookupByLibrary.simpleMessage("天气获取失败,请重新尝试"),
|
||||
|
@ -4,7 +4,6 @@ import 'package:todo_list/config/api_service.dart';
|
||||
import 'package:todo_list/i10n/localization_intl.dart';
|
||||
import 'package:todo_list/json/common_bean.dart';
|
||||
import 'package:todo_list/model/all_model.dart';
|
||||
import 'package:todo_list/utils/full_screen_dialog_util.dart';
|
||||
import 'package:todo_list/utils/shared_util.dart';
|
||||
import 'package:todo_list/widgets/net_loading_widget.dart';
|
||||
|
||||
|
@ -41,6 +41,12 @@ class GlobalLogic{
|
||||
return themeType == MyTheme.darkTheme ? Colors.grey[800] : Theme.of(context).primaryColor;
|
||||
}
|
||||
|
||||
//当为夜间模式时候,黑色替换为白色
|
||||
Color getbwInDark(){
|
||||
final themeType = _model.currentThemeBean.themeType;
|
||||
return themeType == MyTheme.darkTheme ? Colors.white : Colors.black;
|
||||
}
|
||||
|
||||
Future getCurrentLanguageCode() async{
|
||||
final list = await SharedUtil.instance.getStringList(Keys.currentLanguageCode);
|
||||
if (list == null) return;
|
||||
|
@ -5,6 +5,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:todo_list/config/provider_config.dart';
|
||||
import 'package:todo_list/database/database.dart';
|
||||
import 'package:todo_list/i10n/localization_intl.dart';
|
||||
import 'package:todo_list/items/task_item.dart';
|
||||
import 'package:todo_list/json/color_bean.dart';
|
||||
import 'package:todo_list/json/task_bean.dart';
|
||||
@ -13,6 +14,7 @@ import 'package:todo_list/pages/search_page.dart';
|
||||
import 'package:todo_list/utils/file_util.dart';
|
||||
import 'package:todo_list/utils/shared_util.dart';
|
||||
import 'package:todo_list/utils/theme_util.dart';
|
||||
import 'package:todo_list/widgets/edit_dialog.dart';
|
||||
import 'package:todo_list/widgets/scale_animation_widget.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
|
||||
@ -72,6 +74,13 @@ class MainPageLogic {
|
||||
_model.tasks.addAll(tasks);
|
||||
}
|
||||
|
||||
Future getCurrentUserName() async{
|
||||
final currentUserName = await SharedUtil.instance.getString(Keys.currentUserName);
|
||||
if (currentUserName == null) return;
|
||||
if (currentUserName == _model.currentUserName) return;
|
||||
_model.currentUserName = currentUserName;
|
||||
}
|
||||
|
||||
Decoration getBackground(GlobalModel globalModel) {
|
||||
bool isBgGradient = globalModel.isBgGradient;
|
||||
bool isBgChangeWithCard = globalModel.isBgChangeWithCard;
|
||||
@ -219,6 +228,31 @@ class MainPageLogic {
|
||||
}));
|
||||
}
|
||||
|
||||
void onUserNameTap(){
|
||||
final context = _model.context;
|
||||
showDialog(context: context, builder: (ctx){
|
||||
return EditDialog(
|
||||
title: DemoLocalizations.of(context).customUserName,
|
||||
hintText: DemoLocalizations.of(context).inputUserName,
|
||||
onValueChanged: (text){
|
||||
_model.currentUserName = text;
|
||||
},
|
||||
initialValue: _model.currentUserName,
|
||||
onSure: (){
|
||||
if(_model.currentUserName.isEmpty){
|
||||
showDialog(context: context, builder: (ctx){
|
||||
return AlertDialog(content: Text(DemoLocalizations.of(context).userNameCantBeNull),);
|
||||
});
|
||||
return;
|
||||
}
|
||||
SharedUtil.instance.saveString(Keys.currentUserName, _model.currentUserName);
|
||||
_model.refresh();
|
||||
},
|
||||
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
void onSearchTap(){
|
||||
Navigator.of(_model.context).push(new CupertinoPageRoute(builder: (ctx){
|
||||
return ProviderConfig.getInstance().getSearchPage();
|
||||
|
@ -21,6 +21,9 @@ class MainPageModel extends ChangeNotifier {
|
||||
//当前的头像url,比如本地的就是本地路径,网络就是网络地址
|
||||
String currentAvatarUrl = "images/icon.png";
|
||||
|
||||
//当前的用户名
|
||||
String currentUserName = "";
|
||||
|
||||
//是否开启天气
|
||||
bool enableWeatherShow = false;
|
||||
|
||||
@ -39,6 +42,7 @@ class MainPageModel extends ChangeNotifier {
|
||||
[
|
||||
logic.getTasks(),
|
||||
logic.getCurrentAvatar(),
|
||||
logic.getCurrentUserName(),
|
||||
],
|
||||
).then((value) {
|
||||
refresh();
|
||||
|
@ -63,7 +63,7 @@ class _ImagePageState extends State<ImagePage> {
|
||||
builder: (BuildContext context, int index) {
|
||||
final url = widget.imageUrls[index];
|
||||
return PhotoViewGalleryPageOptions(
|
||||
imageProvider: url == NavHeadType.dailyPicUrl ? Image.network(url) : CachedNetworkImageProvider(url),
|
||||
imageProvider: url == NavHeadType.dailyPicUrl ? NetworkImage(url) : CachedNetworkImageProvider(url),
|
||||
initialScale: PhotoViewComputedScale.contained,
|
||||
heroTag: "tag_${index}",
|
||||
);
|
||||
|
@ -82,11 +82,30 @@ class MainPage extends StatelessWidget {
|
||||
margin: EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(top: 20, left: 12),
|
||||
child: Text(
|
||||
"${DemoLocalizations.of(context).welcomeWord}Old Li.",
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
color: globalModel.logic.getWhiteInDark()),
|
||||
child: SingleChildScrollView(
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Flexible(
|
||||
child: InkWell(
|
||||
onTap: model.currentUserName.isEmpty ? null : model.logic.onUserNameTap,
|
||||
child: Text(
|
||||
"${DemoLocalizations.of(context).welcomeWord}${model.currentUserName}",
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
color: globalModel.logic.getWhiteInDark()),
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
model.currentUserName.isEmpty
|
||||
? IconButton(
|
||||
icon: Icon(Icons.account_circle, color: globalModel.logic.getWhiteInDark(),),
|
||||
onPressed: model.logic.onUserNameTap,
|
||||
)
|
||||
: SizedBox()
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -105,12 +124,13 @@ class MainPage extends StatelessWidget {
|
||||
model.tasks.length == 0
|
||||
? model.logic.getEmptyWidget(globalModel)
|
||||
: Container(
|
||||
margin: EdgeInsets.only(top: 40,bottom: 40),
|
||||
margin: EdgeInsets.only(top: 40, bottom: 40),
|
||||
child: CarouselSlider(
|
||||
items: model.logic.getCards(context),
|
||||
aspectRatio: 16 / 9,
|
||||
aspectRatio: 16 / 9,
|
||||
height: min(size.width, size.height) - 100,
|
||||
viewportFraction: size.height >= size.width ? 0.8 : 0.5,
|
||||
viewportFraction:
|
||||
size.height >= size.width ? 0.8 : 0.5,
|
||||
initialPage: 0,
|
||||
enableInfiniteScroll: model.tasks.length >= 3 &&
|
||||
globalModel.enableInfiniteScroll,
|
||||
|
@ -9,6 +9,7 @@ import 'package:todo_list/i10n/localization_intl.dart';
|
||||
import 'package:todo_list/model/global_model.dart';
|
||||
import 'package:todo_list/utils/permission_request_util.dart';
|
||||
import 'package:todo_list/utils/shared_util.dart';
|
||||
import 'package:todo_list/widgets/edit_dialog.dart';
|
||||
import 'package:todo_list/widgets/net_loading_widget.dart';
|
||||
|
||||
import 'all_page.dart';
|
||||
@ -154,55 +155,33 @@ class SettingPage extends StatelessWidget {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text(DemoLocalizations.of(context).enableWeatherShow),
|
||||
content: Form(
|
||||
autovalidate: true,
|
||||
child: TextFormField(
|
||||
initialValue: globalModel.currentPosition,
|
||||
validator: (text){
|
||||
globalModel.currentPosition = text;
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: DemoLocalizations.of(context).inputCurrentCity,
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(
|
||||
DemoLocalizations.of(context).cancel,
|
||||
style: TextStyle(color: Colors.redAccent),
|
||||
),
|
||||
),
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
if(globalModel.currentPosition.isEmpty) return;
|
||||
CancelToken cancelToken = CancelToken();
|
||||
showDialog(context: context, builder: (ctx){
|
||||
return NetLoadingWidget(
|
||||
onRequest: (){
|
||||
globalModel.logic.getWeatherNow(globalModel.currentPosition,controller: globalModel.loadingController);
|
||||
},
|
||||
cancelToken: cancelToken,
|
||||
errorText: DemoLocalizations.of(context).weatherGetWrong,
|
||||
loadingText: DemoLocalizations.of(context).weatherGetting,
|
||||
successText: DemoLocalizations.of(context).weatherSuccess,
|
||||
onSuccess: (){
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
loadingController: globalModel.loadingController,
|
||||
);
|
||||
});
|
||||
},
|
||||
child: Text(DemoLocalizations.of(context).ok,
|
||||
style: TextStyle(color: Colors.greenAccent)),
|
||||
),
|
||||
],
|
||||
return EditDialog(
|
||||
title: DemoLocalizations.of(context).enableWeatherShow,
|
||||
hintText: DemoLocalizations.of(context).inputCurrentCity,
|
||||
initialValue: globalModel.currentPosition,
|
||||
onValueChanged: (text){
|
||||
globalModel.currentPosition = text;
|
||||
},
|
||||
sureTextStyle: TextStyle(color: globalModel.logic.getbwInDark()),
|
||||
onSure: (){
|
||||
if(globalModel.currentPosition.isEmpty) return;
|
||||
CancelToken cancelToken = CancelToken();
|
||||
showDialog(context: context, builder: (ctx){
|
||||
return NetLoadingWidget(
|
||||
onRequest: (){
|
||||
globalModel.logic.getWeatherNow(globalModel.currentPosition,controller: globalModel.loadingController);
|
||||
},
|
||||
cancelToken: cancelToken,
|
||||
errorText: DemoLocalizations.of(context).weatherGetWrong,
|
||||
loadingText: DemoLocalizations.of(context).weatherGetting,
|
||||
successText: DemoLocalizations.of(context).weatherSuccess,
|
||||
onSuccess: (){
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
loadingController: globalModel.loadingController,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
},);
|
||||
} else {
|
||||
|
60
lib/widgets/edit_dialog.dart
Normal file
60
lib/widgets/edit_dialog.dart
Normal file
@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:todo_list/i10n/localization_intl.dart';
|
||||
|
||||
class EditDialog extends StatelessWidget {
|
||||
final VoidCallback onSure;
|
||||
final String title;
|
||||
final String hintText;
|
||||
final String initialValue;
|
||||
final ValueChanged<String> onValueChanged;
|
||||
final TextStyle cancelTextStyle;
|
||||
final TextStyle sureTextStyle;
|
||||
|
||||
const EditDialog({
|
||||
Key key,
|
||||
this.onSure,
|
||||
this.title,
|
||||
this.hintText,
|
||||
this.initialValue, this.onValueChanged, this.cancelTextStyle, this.sureTextStyle,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(title ?? ""),
|
||||
content: Form(
|
||||
autovalidate: true,
|
||||
child: TextFormField(
|
||||
initialValue: initialValue ?? "",
|
||||
validator: (text){
|
||||
if(onValueChanged != null)
|
||||
onValueChanged(text);
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: hintText ?? "",
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(
|
||||
DemoLocalizations.of(context).cancel,
|
||||
style:cancelTextStyle ?? TextStyle(color: Colors.redAccent),
|
||||
),
|
||||
),
|
||||
FlatButton(
|
||||
onPressed: (){
|
||||
if(onSure != null) onSure();
|
||||
Navigator.pop(context);
|
||||
|
||||
},
|
||||
child: Text(DemoLocalizations.of(context).ok,
|
||||
style:sureTextStyle ?? TextStyle(color: Colors.black)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -543,6 +543,24 @@
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"customUserName": "Setting your username",
|
||||
"@customUserName": {
|
||||
"description": "昵称设置",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"inputUserName": "input your username",
|
||||
"@inputUserName": {
|
||||
"description": "输入你的昵称吧",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"userNameCantBeNull": "username can not be empty",
|
||||
"@userNameCantBeNull": {
|
||||
"description": "昵称不能为空哦!",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"taskItems": "{taskNumbers,plural, =0{You have never written a list of tasks.\nLet''s get started soon.}=1{This is your todo-list,\nToday, you have 1 task to complete. }many{This is your todo-list,\nToday, you have {taskNumbers} tasks to complete. }other{This is your todo-list,\nToday, you have {taskNumbers} tasks to complete. }}",
|
||||
"@taskItems": {
|
||||
"type": "text",
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"@@last_modified": "2019-07-25T11:08:23.468694",
|
||||
"@@last_modified": "2019-07-25T17:55:44.478744",
|
||||
"appName": "One Day List",
|
||||
"@appName": {
|
||||
"description": "app的名字",
|
||||
@ -440,6 +440,24 @@
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"customUserName": "Setting your username",
|
||||
"@customUserName": {
|
||||
"description": "昵称设置",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"inputUserName": "input your username",
|
||||
"@inputUserName": {
|
||||
"description": "输入你的昵称吧",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"userNameCantBeNull": "username can not be empty",
|
||||
"@userNameCantBeNull": {
|
||||
"description": "昵称不能为空哦!",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"pink": "pink",
|
||||
"@pink": {
|
||||
"description": "主题颜色",
|
||||
|
@ -542,6 +542,24 @@
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"customUserName": "昵称设置",
|
||||
"@customUserName": {
|
||||
"description": "昵称设置",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"inputUserName": "输入你的昵称吧",
|
||||
"@inputUserName": {
|
||||
"description": "输入你的昵称吧",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"userNameCantBeNull": "昵称不能为空哦!",
|
||||
"@userNameCantBeNull": {
|
||||
"description": "昵称不能为空哦!",
|
||||
"type": "text",
|
||||
"placeholders": {}
|
||||
},
|
||||
"taskItems": "{taskNumbers,plural, =0{你还没有写过任务清单呢.\n快快开始吧.}=1{下面你的任务清单,\n今天, 你有 1 项任务尚未完成. }many{下面是你的任务清单,\n今天, 你有 {taskNumbers} 份任务尚未完成. }other{下面是你的任务清单,\n今天, 你有 {taskNumbers} 份任务尚未完成. }}",
|
||||
"@taskItems": {
|
||||
"type": "text",
|
||||
|
Reference in New Issue
Block a user