diff options
author | Felipe Erias <felipeerias@igalia.com> | 2021-11-05 14:40:43 +0900 |
---|---|---|
committer | Felipe Erias <felipeerias@igalia.com> | 2021-11-05 14:40:43 +0900 |
commit | c0e6b9c068a73c6e77be6a3fedaa7dc603a790aa (patch) | |
tree | cd4b94ada710a0f6c859e5e4fe7fb1532b1452bb /lib/widget_clock.dart | |
parent | a3d903e6b27a12bc2472972e585c351710418e42 (diff) |
Basic structure
Diffstat (limited to 'lib/widget_clock.dart')
-rw-r--r-- | lib/widget_clock.dart | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/widget_clock.dart b/lib/widget_clock.dart new file mode 100644 index 0000000..c66a659 --- /dev/null +++ b/lib/widget_clock.dart @@ -0,0 +1,74 @@ +import 'dart:async'; + +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; + +class ClockWiddget extends StatefulWidget { + final double size; + + const ClockWiddget({Key? key, required this.size}) : super(key: key); + + @override + _ClockWiddgetState createState() => _ClockWiddgetState(); +} + +class _ClockWiddgetState extends State<ClockWiddget> { + late Timer _timer; + DateTime _now = DateTime.now(); + + @override + void initState() { + _now = DateTime.now(); + _timer = new Timer.periodic( + Duration(seconds: 1), + (Timer timer) { + setState(() { + _now = DateTime.now(); + }); + }, + ); + super.initState(); + } + + @override + void dispose() { + _timer.cancel(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Container( + height: widget.size, + padding: EdgeInsets.all(16.0), + decoration: BoxDecoration( + border: Border( + top: BorderSide( + width: 1.0, + ), + ), + ), + child: Column( + children: [ + FittedBox( + fit: BoxFit.contain, + child: Text( + DateFormat('EEEE').format(_now), + style: Theme.of(context).textTheme.headline2, + ), + ), + const Divider(thickness: 1), + FittedBox( + fit: BoxFit.contain, + child: Text( + DateFormat.jm().format(_now), + style: Theme.of(context).textTheme.headline2, + ), + ), + ], + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + ), + alignment: Alignment.center, + ); + } +} |