aboutsummaryrefslogtreecommitdiff
path: root/lib/pages/Home.dart
blob: d4c8d19cd3abe0e3dde12bff01f2880f61e56d68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

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();

  @override
  Widget build(BuildContext ctx) {
    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')),
                       ],
                   ),
               )
             ),
            ),
          );
        }
    );
  }
}