aboutsummaryrefslogtreecommitdiff
path: root/lib/pages/Home.dart
blob: 8913fdb13ab31db6623e32d9e4450442e536875c (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(timeFormat.format(snapshot.data),
                      key: Key('time'),
                      textAlign: TextAlign.left,
                      style: const TextStyle(
                          fontSize: 32.0,
                          fontWeight: FontWeight.bold,
                      ),
                  ),
                  Text(dateFormat.format(snapshot.data),
                      key: Key('date'),
                      textAlign: TextAlign.left,
                      style: const TextStyle(
                          fontSize: 20.0,
                      ),
                  ),
                ]
            );
          }

          return Container(
            height: 300,
            padding: EdgeInsets.symmetric(vertical: 8.0),
            child: Align(alignment: Alignment.topLeft, 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')),
                       ],
                   ),
               )
             ),
            ),
          );
        }
    );
  }
}