diff options
Diffstat (limited to '')
| -rw-r--r-- | TODO.md | 1 | ||||
| -rw-r--r-- | lib/main.dart | 2 | ||||
| -rw-r--r-- | lib/pages/Home.dart | 77 | ||||
| -rw-r--r-- | test/homeview_test.dart | 26 |
4 files changed, 79 insertions, 27 deletions
@@ -7,6 +7,7 @@ ## HomePage - [ ] Create statusbar + - [ ] Get rid of defaultTime and loading - [ ] Create favorites list - [ ] Get favorites list from a persistent store diff --git a/lib/main.dart b/lib/main.dart index 64db33a..dba8ce6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -25,7 +25,7 @@ class MyApp extends StatelessWidget { body: PageView( controller: PageController(), children: [ - HomeView(time$: time$), + HomeView(time$, defaultTime: DateTime.now()), AppsView(), ], ), diff --git a/lib/pages/Home.dart b/lib/pages/Home.dart index f2809db..d4c8d19 100644 --- a/lib/pages/Home.dart +++ b/lib/pages/Home.dart @@ -2,40 +2,69 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; -class HomeView extends StatelessWidget { +class StatusInfoCard extends StatelessWidget { Stream<DateTime> time$; DateTime defaultTime; + StatusInfoCard(this.time$, { this.defaultTime }): super(); + final timeFormat = new DateFormat.jm(); // hm fr 24 hrs final dateFormat = DateFormat('d MMMM'); + + @override + Widget build(BuildContext 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 = Column(children: [ + Text(timeFormat.format(snapshot.data), key: Key('time')), + Text(dateFormat.format(snapshot.data), key: Key('date')), + ]); + } + + return Container( + height: 300, + child: child, + ); + }, + ); + } +} + +class HomeView extends StatelessWidget { + Stream<DateTime> time$; + DateTime defaultTime; - HomeView({ this.time$, this.defaultTime }): super(); + HomeView(this.time$, { this.defaultTime }): super(); @override Widget build(BuildContext ctx) { - return Container( - padding: const EdgeInsets.symmetric(vertical: 32.0, horizontal: 16.0), - child: Column( - children: [ - StreamBuilder<DateTime>( - stream: time$, - initialData: defaultTime, - builder: (BuildContext context, AsyncSnapshot<DateTime> snapshot) { - switch (snapshot.connectionState) { - case ConnectionState.active: - case ConnectionState.done: - return Column(children: [ - Text(timeFormat.format(snapshot.data), key: Key('time')), - Text(dateFormat.format(snapshot.data), key: Key('date')), - ]); - default: - return Text('Loading...', key: Key('loading')); - } - }, + return LayoutBuilder( + builder: (BuildContext context, BoxConstraints viewportConstraints) { + return SingleChildScrollView( + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: viewportConstraints.maxHeight, + ), + child: IntrinsicHeight( + child: Container( + padding: const EdgeInsets.symmetric(vertical: 36.0, horizontal: 16.0), + height: viewportConstraints.maxHeight, + child: Column( + children: [ + StatusInfoCard(time$, defaultTime: defaultTime), + Expanded(child: Text('Content')), + ], + ), + ) + ), ), - Expanded(child: Text('Content')), - ], - ), + ); + } ); } } diff --git a/test/homeview_test.dart b/test/homeview_test.dart index aa193df..e291cca 100644 --- a/test/homeview_test.dart +++ b/test/homeview_test.dart @@ -5,17 +5,18 @@ import 'package:owyn/pages/Home.dart'; import 'utils.dart'; +Future<void> waitFor(Duration duration) { return Future.delayed(duration, () {}); } void main() { DateTime time = DateTime.utc(2020, DateTime.march, 7, 10, 25, 30); Stream<DateTime> time$ = Stream.value(time).asBroadcastStream(); testWidgets('Should render with no errors', (WidgetTester tester) async { - await tester.pumpWidget(wrapper(HomeView(time$: time$))); + await tester.pumpWidget(wrapper(HomeView(time$))); }); testWidgets('Should show formatted default date correctly', (WidgetTester tester) async { - await tester.pumpWidget(wrapper(HomeView(time$: time$, defaultTime: time))); + await tester.pumpWidget(wrapper(HomeView(time$, defaultTime: time))); await tester.pump(); var timeWidget = find.byKey(Key('time')); @@ -31,4 +32,25 @@ void main() { expect(w.widget.toString(), contains('7 March')); } }); + + testWidgets('Should show streamed formatted date correctly', (WidgetTester tester) async { + await tester.pumpWidget(wrapper(HomeView(time$))); + await tester.pump(); + + var timeWidget = find.byKey(Key('time')); + var dateWidget = find.byKey(Key('date')); + + await waitFor(Duration(milliseconds: 50)); + await tester.pump(); + + expect(timeWidget, findsOneWidget); + //for(var w in timeWidget.evaluate()) { + //expect(w.widget.toString(), contains('10:25 AM')); + //} + + //expect(dateWidget, findsOneWidget); + //for(var w in dateWidget.evaluate()) { + //expect(w.widget.toString(), contains('7 March')); + //} + }); } |
