Started using StoreConnector in prototype screen

now changes cause rebuilds

Signed-off-by: Andreas Fahrecker <AndreasFahrecker@gmail.com>
This commit is contained in:
Andreas Fahrecker 2020-10-16 11:19:55 +02:00
parent 4b7adc6e45
commit 7f6eec43de

View File

@ -64,21 +64,22 @@ class _ProgressScreenState extends State<ProgressScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Store<AppState> store = StoreProvider.of<AppState>(context);
final int daysDone =
DateTime.now().difference(store.state.timers[0].startTime).inDays;
final int daysLeft =
store.state.timers[0].endTime.difference(DateTime.now()).inDays;
final int allDays = store.state.timers[0].endTime
.difference(store.state.timers[0].startTime)
.inDays;
final double percent = daysDone / (allDays / 100) / 100;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("${widget.name} Progress"), title: Text("${widget.name} Progress"),
), ),
body: Container( body: StoreConnector(
converter: _ViewModel.fromStore,
builder: (context, _ViewModel vm) {
final int daysDone =
DateTime.now().difference(vm.timer.startTime).inDays;
final int daysLeft =
vm.timer.endTime.difference(DateTime.now()).inDays;
final int allDays =
vm.timer.endTime.difference(vm.timer.startTime).inDays;
final double percent = daysDone / (allDays / 100) / 100;
return Container(
margin: const EdgeInsets.all(5), margin: const EdgeInsets.all(5),
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
@ -95,8 +96,8 @@ class _ProgressScreenState extends State<ProgressScreen> {
), ),
Expanded( Expanded(
flex: 2, flex: 2,
child: Text("${store.state.timers[0].startTime.toLocal()}" child: Text(
.split(" ")[0]), "${vm.timer.startTime.toLocal()}".split(" ")[0]),
), ),
Expanded( Expanded(
flex: 2, flex: 2,
@ -123,8 +124,8 @@ class _ProgressScreenState extends State<ProgressScreen> {
), ),
Expanded( Expanded(
flex: 2, flex: 2,
child: Text("${store.state.timers[0].endTime.toLocal()}" child: Text(
.split(" ")[0]), "${vm.timer.endTime.toLocal()}".split(" ")[0]),
), ),
Expanded( Expanded(
flex: 2, flex: 2,
@ -168,7 +169,22 @@ class _ProgressScreenState extends State<ProgressScreen> {
), ),
], ],
), ),
), );
}),
);
}
}
class _ViewModel {
final Timer timer;
_ViewModel({
@required this.timer,
});
static _ViewModel fromStore(Store<AppState> store) {
return _ViewModel(
timer: store.state.timers[0],
); );
} }
} }