From 20f1fa5d50b60576594d0ebb434b2ae237ff2cac Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Tue, 2 Jun 2020 21:11:17 +0530 Subject: Additional test cases struggle (failing) --- lib/pages/Home.dart | 77 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 24 deletions(-) (limited to 'lib/pages/Home.dart') 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 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( + stream: time$, + initialData: defaultTime, + builder: (BuildContext context, AsyncSnapshot 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 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( - stream: time$, - initialData: defaultTime, - 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')); - } - }, + 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')), - ], - ), + ); + } ); } } -- cgit v1.3.1