-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
254 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,122 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:mobx/mobx.dart'; | ||
import 'package:todomobx/store/list_store.dart'; | ||
import 'package:todomobx/widgets/custom_icon_button.dart'; | ||
import 'package:todomobx/widgets/custom_text_field.dart'; | ||
|
||
import 'login_screen.dart'; | ||
|
||
class ListScreen extends StatefulWidget { | ||
|
||
@override | ||
_ListScreenState createState() => _ListScreenState(); | ||
@override | ||
_ListScreenState createState() => _ListScreenState(); | ||
} | ||
|
||
class _ListScreenState extends State<ListScreen> { | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SafeArea( | ||
child: Scaffold( | ||
resizeToAvoidBottomInset: false, | ||
body: Container( | ||
margin: const EdgeInsets.fromLTRB(32, 0, 32, 32), | ||
child: Column( | ||
children: <Widget>[ | ||
Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 2), | ||
child: Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: <Widget>[ | ||
Text( | ||
'Tarefas', | ||
style: TextStyle( | ||
color: Colors.white, | ||
fontWeight: FontWeight.w900, | ||
fontSize: 32 | ||
), | ||
), | ||
IconButton( | ||
icon: Icon(Icons.exit_to_app), | ||
color: Colors.white, | ||
onPressed: (){ | ||
Navigator.of(context).pushReplacement( | ||
MaterialPageRoute(builder: (context)=>LoginScreen()) | ||
); | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
Expanded( | ||
child: Card( | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(16), | ||
), | ||
elevation: 16, | ||
child: Padding( | ||
padding: const EdgeInsets.all(16), | ||
child: Column( | ||
children: <Widget>[ | ||
CustomTextField( | ||
hint: 'Tarefa', | ||
onChanged: (todo){ | ||
|
||
}, | ||
suffix: CustomIconButton( | ||
radius: 32, | ||
iconData: Icons.add, | ||
onTap: (){ | ||
|
||
}, | ||
), | ||
), | ||
const SizedBox(height: 8,), | ||
Expanded( | ||
child: ListView.separated( | ||
itemCount: 10, | ||
itemBuilder: (_, index){ | ||
return ListTile( | ||
title: Text( | ||
'Item $index', | ||
), | ||
onTap: (){ | ||
|
||
}, | ||
); | ||
}, | ||
separatorBuilder: (_, __){ | ||
return Divider(); | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
|
||
ListStore _listStore = ListStore(); | ||
|
||
ReactionDisposer disposer; | ||
|
||
@override | ||
void didChangeDependencies() { | ||
disposer = reaction((_) => _listStore.hasUser, (user) { | ||
Navigator.of(context).pushReplacement( | ||
MaterialPageRoute(builder: (context)=>LoginScreen()) | ||
); | ||
}); | ||
super.didChangeDependencies(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
disposer(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SafeArea( | ||
child: Scaffold( | ||
resizeToAvoidBottomInset: false, | ||
body: Container( | ||
margin: const EdgeInsets.fromLTRB(32, 0, 32, 32), | ||
child: Column( | ||
children: <Widget>[ | ||
Padding( | ||
padding: const EdgeInsets.symmetric( | ||
vertical: 16, horizontal: 2), | ||
child: Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: <Widget>[ | ||
Text( | ||
'Tarefas', | ||
style: TextStyle( | ||
color: Colors.white, | ||
fontWeight: FontWeight.w900, | ||
fontSize: 32 | ||
), | ||
), | ||
IconButton( | ||
icon: Icon(Icons.exit_to_app), | ||
color: Colors.white, | ||
onPressed: _listStore.logout, | ||
), | ||
], | ||
), | ||
), | ||
Expanded( | ||
child: Card( | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(16), | ||
), | ||
elevation: 16, | ||
child: Padding( | ||
padding: const EdgeInsets.all(16), | ||
child: Column( | ||
children: <Widget>[ | ||
CustomTextField( | ||
enabled: !_listStore.loading, | ||
hint: 'Tarefa', | ||
onChanged: (todo) { | ||
|
||
}, | ||
suffix: CustomIconButton( | ||
radius: 32, | ||
iconData: Icons.add, | ||
onTap: () { | ||
|
||
}, | ||
), | ||
), | ||
const SizedBox(height: 8,), | ||
Expanded( | ||
child: ListView.separated( | ||
itemCount: 10, | ||
itemBuilder: (_, index) { | ||
return ListTile( | ||
title: Text( | ||
'Item $index', | ||
), | ||
onTap: !_listStore.loading?null:() { | ||
|
||
}, | ||
); | ||
}, | ||
separatorBuilder: (_, __) { | ||
return Divider(); | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:mobx/mobx.dart'; | ||
|
||
part 'list_store.g.dart'; | ||
|
||
class ListStore = _ListStore with _$ListStore; | ||
|
||
abstract class _ListStore with Store { | ||
|
||
@observable | ||
String _newTodo = ""; | ||
|
||
@observable | ||
bool loading = false; | ||
|
||
@observable | ||
bool hasUser = true; | ||
|
||
@action | ||
void updateTodo(String todo) => _newTodo = todo; | ||
|
||
@action | ||
Future<void> logout() async{ | ||
loading = true; | ||
await Future.delayed(Duration(seconds: 2)); | ||
hasUser = false; | ||
loading = false; | ||
} | ||
|
||
@computed | ||
Function get logoutPresses => loading?logout:null; | ||
|
||
ObserverList todoList; | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.