aboutsummaryrefslogtreecommitdiff
path: root/lib/pages/Home.dart
blob: 1f553e326d21dd53cb140ba282e42461705332f3 (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
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 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')),
          ],
      ),
    );
  }
}