From fb1a274bc9b16650d6a85761ad236b90cdbfd41a Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Tue, 2 Jun 2020 19:03:52 +0530 Subject: Adds timer stream to home page --- lib/pages/Home.dart | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'lib/pages') 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 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( + stream: time$, + initialData: DateTime.now(), + builder: (BuildContext context, AsyncSnapshot 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')), + ], + ), + ); } } -- cgit v1.3.1