diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/main.dart | 17 | ||||
| -rw-r--r-- | lib/pages/Home.dart | 41 |
2 files changed, 20 insertions, 38 deletions
diff --git a/lib/main.dart b/lib/main.dart index a223fb7..c41c1ad 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,10 +15,6 @@ void main() { } class MyAppState extends StreamState<MyApp> { - // Streams - final Stream<DateTime> time$ = - Stream.periodic(Duration(seconds: 1), (_x) => DateTime.now()).asBroadcastStream(); - // State final config = StreamStateValue<Config>( stream$: getConfig$(), @@ -28,6 +24,10 @@ class MyAppState extends StreamState<MyApp> { stream$: getFavorites$(), value: [], ); + final dateTime = StreamStateValue<DateTime>( + stream$: Stream.periodic(Duration(seconds: 1), (_x) => DateTime.now()).asBroadcastStream(), + value: DateTime.now(), + ); void initState() { super.initState(); initStateValue(config); @@ -36,12 +36,6 @@ class MyAppState extends StreamState<MyApp> { initFavorites(); } - @override - void dispose() { - super.dispose(); - time$.drain(); - } - ThemeData getLightTheme() { return ThemeData(brightness: Brightness.light); } @@ -84,8 +78,7 @@ class MyAppState extends StreamState<MyApp> { controller: PageController(keepPage: true), children: [ HomeView( - time$: time$, - defaultTime: DateTime.now(), + dateTime: dateTime.value, favoriteApps: favoriteApps.value, ), AppsView(), diff --git a/lib/pages/Home.dart b/lib/pages/Home.dart index 1309596..2930bf8 100644 --- a/lib/pages/Home.dart +++ b/lib/pages/Home.dart @@ -8,10 +8,9 @@ import '../components/FixedContainer.dart'; import '../data/config.dart'; class StatusInfoCard extends StatelessWidget { - Stream<DateTime> time$; - DateTime defaultTime; + DateTime dateTime; - StatusInfoCard(this.time$, { this.defaultTime }): super(); + StatusInfoCard({ this.dateTime }): super(); final timeFormat = DateFormat('h:mm a'); // H fr 24 hrs final dateFormat = DateFormat('EEEE, d MMM'); @@ -20,14 +19,12 @@ class StatusInfoCard extends StatelessWidget { Widget build(BuildContext ctx) { ThemeData theme = Theme.of(ctx); - return StreamBuilder<DateTime>( - stream: time$, - initialData: defaultTime, - builder: (BuildContext context, AsyncSnapshot<DateTime> snapshot) { - Widget child = Text('Loading...', key: Key('loading')); - - if (snapshot.hasData) { - child = Row( + return Container( + height: 100, + padding: EdgeInsets.symmetric(vertical: 8.0), + child: Align( + alignment: Alignment.topLeft, + child: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -35,7 +32,7 @@ class StatusInfoCard extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(timeFormat.format(snapshot.data), + Text(timeFormat.format(dateTime), key: Key('time'), textAlign: TextAlign.left, style: const TextStyle( @@ -43,7 +40,7 @@ class StatusInfoCard extends StatelessWidget { fontWeight: FontWeight.bold, ), ), - Text(dateFormat.format(snapshot.data), + Text(dateFormat.format(dateTime), key: Key('date'), textAlign: TextAlign.left, style: const TextStyle( @@ -71,25 +68,17 @@ class StatusInfoCard extends StatelessWidget { ), ), ], - ); - } - - return Container( - height: 100, - padding: EdgeInsets.symmetric(vertical: 8.0), - child: Align(alignment: Alignment.topLeft, child: child), - ); - }, + ), + ), ); } } class HomeView extends StatelessWidget { - Stream<DateTime> time$; - DateTime defaultTime; + DateTime dateTime; List<Application> favoriteApps; - HomeView({ this.time$, this.defaultTime, this.favoriteApps }): super(); + HomeView({ this.dateTime, this.favoriteApps }): super(); void noop(Application app) {} @@ -99,7 +88,7 @@ class HomeView extends StatelessWidget { padding: const EdgeInsets.symmetric(vertical: 36.0, horizontal: 16.0), child: Column( children: [ - StatusInfoCard(time$, defaultTime: defaultTime), + StatusInfoCard(dateTime: dateTime), Expanded(child: Container( child: AppList(appList: favoriteApps, openApp: noop, openOptionsMenu: noop), )), |
