aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2020-06-02 19:03:52 +0530
committerAkshay Nair <phenax5@gmail.com>2020-06-02 19:03:52 +0530
commitfb1a274bc9b16650d6a85761ad236b90cdbfd41a (patch)
tree3708c1971d99efedf697208a2665e128df12a4cd /lib
parent08c52d1b09eaf78a0fdba9d808ed1669430b34f6 (diff)
downloaddaft-launcher-fb1a274bc9b16650d6a85761ad236b90cdbfd41a.tar.gz
daft-launcher-fb1a274bc9b16650d6a85761ad236b90cdbfd41a.zip
Adds timer stream to home page
Diffstat (limited to 'lib')
-rw-r--r--lib/main.dart16
-rw-r--r--lib/pages/Home.dart34
2 files changed, 45 insertions, 5 deletions
diff --git a/lib/main.dart b/lib/main.dart
index 9397dc9..64db33a 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -1,3 +1,4 @@
+import 'dart:async';
import 'package:flutter/material.dart';
import 'pages/Home.dart';
@@ -8,17 +9,24 @@ void main() {
}
class MyApp extends StatelessWidget {
+ final Stream<DateTime> time$ = Stream.periodic(Duration(seconds: 1), (_x) => DateTime.now()).asBroadcastStream();
+
+ @override
+ void dispose() {
+ time$.drain();
+ }
+
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
- title: 'Flutter Demo',
+ title: 'owyn launcher',
home: Scaffold(
body: PageView(
- controller: PageViewController(),
+ controller: PageController(),
children: [
- HomeView(),
- AppView(),
+ HomeView(time$: time$),
+ AppsView(),
],
),
),
diff --git a/lib/pages/Home.dart b/lib/pages/Home.dart
index 32b8729..1f553e3 100644
--- a/lib/pages/Home.dart
+++ b/lib/pages/Home.dart
@@ -1,9 +1,41 @@
+import 'dart:async';
import 'package:flutter/material.dart';
+import 'package:intl/intl.dart';
class HomeView extends StatelessWidget {
+ Stream<DateTime> time$;
+
+ final timeFormat = new DateFormat.jm();
+ final dateFormat = DateFormat('d, MMM');
+
+ HomeView({ this.time$ }): super();
+
@override
Widget build(BuildContext ctx) {
- return Text('Home');
+ return Container(
+ padding: const EdgeInsets.symmetric(vertical: 32.0, horizontal: 16.0),
+ child: Column(
+ children: [
+ StreamBuilder<DateTime>(
+ stream: time$,
+ initialData: DateTime.now(),
+ 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'));
+ }
+ },
+ ),
+ Expanded(child: Text('Content')),
+ ],
+ ),
+ );
}
}