1.新增 progress 进度为100时显示

2.主页面与次页面数据共享
This commit is contained in:
oldchen
2019-07-01 18:55:14 +08:00
parent c9db706af8
commit c5328f7a09
21 changed files with 140 additions and 77 deletions

View File

@ -16,7 +16,6 @@ class ProviderConfig{
ProviderConfig._internal();
ChangeNotifierProvider<GlobalModel> getGlobal(Widget child) {
return ChangeNotifierProvider<GlobalModel>(
builder: (context) => GlobalModel(),
@ -31,14 +30,12 @@ class ProviderConfig{
);
}
ChangeNotifierProvider<TaskDetailPageModel> getTaskDetailPage(int index, TaskBean taskBean){
ChangeNotifierProvider<TaskDetailPageModel> getTaskDetailPage(
int index, TaskBean taskBean,
{MainPageModel mainPageModel}) {
return ChangeNotifierProvider<TaskDetailPageModel>(
builder: (context) => TaskDetailPageModel(taskBean),
child: TaskDetailPage(index),
child: TaskDetailPage(index,mainPageModel: mainPageModel,),
);
}
}

View File

@ -18,6 +18,10 @@ class DemoLocalizations {
return Localizations.of<DemoLocalizations>(context, DemoLocalizations);
}
String get appName{
return Intl.message("One Day",name: "appName",desc: "app的名字");
}
String get languageTitle {
return Intl.message(
'Change Language',

View File

@ -26,6 +26,7 @@ class MessageLookup extends MessageLookupByLibrary {
final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"appName" : MessageLookupByLibrary.simpleMessage("One Day"),
"itemNumber" : m0,
"languageTitle" : MessageLookupByLibrary.simpleMessage("Change Language"),
"taskItems" : m1,

View File

@ -26,6 +26,7 @@ class MessageLookup extends MessageLookupByLibrary {
final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function> {
"appName" : MessageLookupByLibrary.simpleMessage("一日"),
"itemNumber" : m0,
"languageTitle" : MessageLookupByLibrary.simpleMessage("切换语言"),
"taskItems" : m1,

View File

@ -11,7 +11,8 @@ class TaskDetailItem extends StatefulWidget {
{this.itemProgress = 0.0,
this.onChecked,
@required this.itemName,
this.index = 0, this.onProgressChanged});
this.index = 0,
this.onProgressChanged});
@override
_TaskDetailItemState createState() => _TaskDetailItemState();
@ -35,7 +36,7 @@ class _TaskDetailItemState extends State<TaskDetailItem>
CurvedAnimation(parent: _controller, curve: Curves.easeOutBack));
Future.delayed(
Duration(
seconds: 1,
milliseconds: 600,
), () {
_controller.forward();
});
@ -104,6 +105,12 @@ class _TaskDetailItemState extends State<TaskDetailItem>
),
child: Text("${widget.itemName}")),
)),
Expanded(
flex: 1,
child: progressShow ? SizedBox() : Text(
"${(currentProgress * 100).toInt()}%",
style: TextStyle(fontSize: 8),
)),
Expanded(
flex: 1,
child: IconButton(

View File

@ -38,7 +38,7 @@ class TaskItem extends StatelessWidget {
index,
space: width / 3,
taskName: taskBean?.taskName??"",
taskNumbers: taskBean?.taskDetailNum??0,
taskNumbers: taskBean?.detailList?.length??0,
overallProgress: taskBean?.overallProgress??0.0,
)))),
],

View File

@ -35,8 +35,8 @@ class TaskBean {
{
"taskName":"读书",
"taskType":"read_book",
"taskDetailNum":3,
"overallProgress":0.5,
"taskDetailNum":4,
"overallProgress":0.75,
"detailList":[
{
"taskDetailName":"白夜行",
@ -50,6 +50,10 @@ class TaskBean {
"taskDetailName":"恶意",
"itemProgress":1.0,
},
{
"taskDetailName":"谁杀了他",
"itemProgress":1.0,
},
],
},
{

View File

@ -20,9 +20,9 @@ class MainPageLogic{
onTap: () {
Navigator.of(context).push(new PageRouteBuilder(
pageBuilder: (ctx, anm, anmS) {
return ProviderConfig.getInstance().getTaskDetailPage(index,taskBean);
return ProviderConfig.getInstance().getTaskDetailPage(index,taskBean,mainPageModel: _model);
},
transitionDuration: Duration(seconds: 1)));
transitionDuration: Duration(milliseconds: 800)));
},
);
});

View File

@ -1,3 +1,4 @@
import 'package:todo_list/json/task_bean.dart';
import 'package:todo_list/model/all_model.dart';
class TaskDetailPageLogic{
@ -12,7 +13,15 @@ class TaskDetailPageLogic{
for(int i = 0; i < length;i++){
overallProgress += _model.taskBean.detailList[i].itemProgress / length;
}
_model.taskBean.overallProgress = overallProgress;
return overallProgress;
}
void refreshProgress(TaskDetailBean taskDetailBean, progress, MainPageModel model) {
taskDetailBean.itemProgress = progress;
getOverallProgress();
model.refresh();
_model.refresh();
}
}

View File

@ -10,11 +10,9 @@ import 'package:todo_list/utils/shared_util.dart';
import 'i10n/localization_intl.dart';
void main() {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
runApp(
ProviderConfig.getInstance().getGlobal(MyApp()),
);
}
@ -24,15 +22,10 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final model = Provider.of<GlobalModel>(context);
SharedUtil.instance.getStringList(Keys.currentLanguage).then((list){
if(list == null) return;
if(list == model.currentLanguage) return;
model.currentLanguage = list;
model.refresh();
});
model.setContext(context);
return MaterialApp(
title: 'ToDo List',
title: model.appName,
localizationsDelegates: [
// ... app-specific localization delegate[s] here
GlobalMaterialLocalizations.delegate,
@ -47,8 +40,7 @@ class MyApp extends StatelessWidget {
(Locale locale, Iterable<Locale> supportedLocales) {},
localeListResolutionCallback:
(List<Locale> locales, Iterable<Locale> supportedLocales) {
debugPrint(
"locales:${locales} supportedLocales${supportedLocales} ");
debugPrint("app:${model.appName}");
},
locale: Locale(model.currentLanguage[0], model.currentLanguage[1]),
theme: ThemeData(

View File

@ -1,10 +1,13 @@
import 'package:flutter/material.dart';
import 'package:todo_list/logic/all_logic.dart';
import 'package:todo_list/utils/shared_util.dart';
class GlobalModel extends ChangeNotifier {
GlobalLogic logic;
BuildContext context;
String appName = "One Day";
List<String> currentLanguage = ["zh", "CN"];
@ -17,6 +20,12 @@ class GlobalModel extends ChangeNotifier{
void setContext(BuildContext context) {
if (this.context == null) {
this.context = context;
SharedUtil.instance.getStringList(Keys.currentLanguage).then((list) {
if (list == null) return;
if (list == currentLanguage) return;
currentLanguage = list;
notifyListeners();
});
}
}

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:todo_list/logic/all_logic.dart';
import 'package:todo_list/json/task_bean.dart';
class MainPageModel extends ChangeNotifier{
MainPageLogic logic;

View File

@ -7,8 +7,7 @@ class TaskDetailPageModel extends ChangeNotifier{
TaskDetailPageLogic logic;
BuildContext context;
bool isExisting = false;
double overallProgress = 0.0;
bool isExiting = false;
TaskBean taskBean;
List<double> progressList = [];
@ -17,7 +16,6 @@ class TaskDetailPageModel extends ChangeNotifier{
TaskDetailPageModel(TaskBean taskBean){
logic = TaskDetailPageLogic(this);
this.taskBean = taskBean;
this.overallProgress = taskBean?.overallProgress??0.0;
this.progressList.clear();
}

View File

@ -28,6 +28,7 @@ class LanguagePage extends StatelessWidget {
onTap: () {
final model = Provider.of<GlobalModel>(context);
model.currentLanguage = [languageCode,countruCode];
model.appName = DemoLocalizations.of(context).appName;
model.refresh();
SharedUtil.instance.saveStringList(Keys.currentLanguage, [languageCode, countruCode]);
},

View File

@ -16,7 +16,7 @@ class MainPage extends StatelessWidget {
backgroundColor: Theme.of(context).primaryColor,
appBar: AppBar(
elevation: 0,
title: Text("ToDo List"),
title: Text(DemoLocalizations.of(context).appName),
leading: IconButton(
icon: Icon(Icons.keyboard_arrow_down,color: Colors.white,size: 35,),
onPressed: () {

View File

@ -2,13 +2,15 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:todo_list/items/task_detail_item.dart';
import 'package:todo_list/json/task_bean.dart';
import 'package:todo_list/model/main_page_model.dart';
import 'package:todo_list/model/task_detail_page_model.dart';
import 'package:todo_list/widgets/task_info_widget.dart';
class TaskDetailPage extends StatelessWidget {
final int index;
final MainPageModel mainPageModel;
TaskDetailPage(this.index);
TaskDetailPage(this.index, {this.mainPageModel});
@override
Widget build(BuildContext context) {
@ -16,7 +18,7 @@ class TaskDetailPage extends StatelessWidget {
return WillPopScope(
onWillPop: () {
model.isExisting = true;
model.isExiting = true;
model.refresh();
Navigator.of(context).pop();
},
@ -37,7 +39,8 @@ class TaskDetailPage extends StatelessWidget {
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
model.isExisting = true;
model.isExiting = true;
model.refresh();
Navigator.of(context).pop();
}),
@ -60,30 +63,29 @@ class TaskDetailPage extends StatelessWidget {
margin: EdgeInsets.only(left: 50, top: 20, right: 50),
child: TaskInfoWidget(
index,
taskNumbers: model?.taskBean?.taskDetailNum??0,
taskNumbers: model?.taskBean?.detailList?.length??0,
taskName: model?.taskBean?.taskName??"",
overallProgress: model.overallProgress,
overallProgress: model.taskBean?.overallProgress??0.0,
)),
Expanded(
child: Container(
margin: EdgeInsets.only(
left: 50, top: 20, right: 50, bottom: 20),
child: !model.isExisting
child: !model.isExiting
? ListView(
children:
List.generate(model?.taskBean?.detailList?.length??0, (index) {
TaskDetailBean taskDetailBean = model.taskBean.detailList[index];
return TaskDetailItem(
index: index,
itemProgress: taskDetailBean.itemProgress,
itemName: taskDetailBean.taskDetailName,
onProgressChanged: (progress){
taskDetailBean.itemProgress = progress;
model.overallProgress = model.logic.getOverallProgress();
model.logic.refreshProgress(taskDetailBean, progress, mainPageModel);
model.refresh();
},
onChecked: (progress){
taskDetailBean.itemProgress = progress;
model.overallProgress = model.logic.getOverallProgress();
model.logic.refreshProgress(taskDetailBean, progress, mainPageModel);
model.refresh();
},
);
@ -98,4 +100,5 @@ class TaskDetailPage extends StatelessWidget {
),
);
}
}

View File

@ -67,7 +67,11 @@ class TaskInfoWidget extends StatelessWidget {
SizedBox(
height: space,
),
Container(
Row(
children: <Widget>[
Expanded(
flex: 9,
child: Container(
alignment: Alignment.bottomLeft,
child: Hero(
tag: "task_title${index}",
@ -75,11 +79,24 @@ class TaskInfoWidget extends StatelessWidget {
color: Colors.transparent,
child: Text(
"${taskName} ",
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.bold),
),
),
),
),
),
overallProgress == 1.0 ? Expanded(
flex: 1,
child: Hero(
tag: "task_complete${index}",
child: Icon(
Icons.check_circle,
color: Colors.greenAccent,
),
)) : SizedBox()
],
),
Container(
margin: EdgeInsets.only(top: 5),
alignment: Alignment.bottomLeft,

View File

@ -1,5 +1,11 @@
{
"@@last_modified": "2019-06-28T17:59:54.925401",
"appName": "One Day",
"@appName": {
"description": "app的名字",
"type": "text",
"placeholders": {}
},
"languageTitle": "Change Language",
"@languageTitle": {
"description": "修改语言",

View File

@ -1,5 +1,11 @@
{
"@@last_modified": "2019-06-29T09:44:38.418387",
"@@last_modified": "2019-07-01T09:59:52.217683",
"appName": "One Day",
"@appName": {
"description": "app的名字",
"type": "text",
"placeholders": {}
},
"languageTitle": "Change Language",
"@languageTitle": {
"description": "修改语言",

View File

@ -1,5 +1,11 @@
{
"@@last_modified": "2019-06-28T15:08:05.980030",
"appName": "一日",
"@appName": {
"description": "app的名字",
"type": "text",
"placeholders": {}
},
"languageTitle": "切换语言",
"@languageTitle": {
"description": "Change Language",

View File

@ -61,6 +61,7 @@ void main(){
test("\n测试\n", (){
List<TaskBean> tasks = TaskBean.fromMapList(getMockData());
print(tasks[0].toString());
});