flutter_countdown_timer 1.3.0 flutter_countdown_timer: ^1.3.0 copied to clipboard
A flutter countdown timer. [10 days 5:30:46] ⬇⬇⬇⬇
import 'package:flutter/material.dart';
import 'package:flutter_countdown_timer/flutter_countdown_timer.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
int endTime = DateTime.now().millisecondsSinceEpoch + 1000 * 60;
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
CountdownTimer(
endTime: endTime,
onEnd: () {
print('onEnd');
},
),
CountdownTimer(
endTime: endTime,
textStyle: TextStyle(fontSize: 30, color: Colors.pink),
),
CountdownTimer(
endTime: endTime,
widgetBuilder: (_, CurrentRemainingTime time) {
if(time == null) {
return Text('Game over');
}
return Text(
'days: [ ${time.days} ], hours: [ ${time.hours} ], min: [ ${time.min} ], sec: [ ${time.sec} ]');
},
),
CountdownTimer(
endTime: endTime,
widgetBuilder: (BuildContext context, CurrentRemainingTime time) {
if(time == null) {
return Text('Game over');
}
List<Widget> list = [];
if(time.days != null) {
list.add(Row(
children: <Widget>[
Icon(Icons.sentiment_dissatisfied),
Text(time.days.toString()),
],
));
}
if(time.hours != null) {
list.add(Row(
children: <Widget>[
Icon(Icons.sentiment_satisfied),
Text(time.hours.toString()),
],
));
}
if(time.min != null) {
list.add(Row(
children: <Widget>[
Icon(Icons.sentiment_very_dissatisfied),
Text(time.min.toString()),
],
));
}
if(time.sec != null) {
list.add(Row(
children: <Widget>[
Icon(Icons.sentiment_very_satisfied),
Text(time.sec.toString()),
],
));
}
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: list,
);
},
),
],
),
);
}
}