Reputation: 31
I'm trying to build an Expanded Widget that would display Days, Hours, Minutes and Seconds remaining (see screenshot).
How can I achieve this?
I've gone through a whole bunch of flutter documentation but yet was unable to correctly create it..
screenshot of the widget I am trying to build
Thanks for the help!
Upvotes: 1
Views: 5176
Reputation: 54365
You can copy paste run full code below
You can use package https://pub.dev/packages/flutter_countdown_timer
code snippet
CountdownTimer(
endTime: 1594829147719,
defaultDays: "==",
defaultHours: "--",
defaultMin: "**",
defaultSec: "++",
daysSymbol: "days",
hoursSymbol: "hrs ",
minSymbol: "min ",
secSymbol: "sec",
daysTextStyle: TextStyle(fontSize: 30, color: Colors.red),
hoursTextStyle: TextStyle(fontSize: 30, color: Colors.orange),
minTextStyle: TextStyle(fontSize: 30, color: Colors.lightBlue),
secTextStyle: TextStyle(fontSize: 30, color: Colors.pink),
daysSymbolTextStyle:
TextStyle(fontSize: 20, color: Colors.green),
hoursSymbolTextStyle:
TextStyle(fontSize: 20, color: Colors.amberAccent),
minSymbolTextStyle:
TextStyle(fontSize: 20, color: Colors.black),
secSymbolTextStyle:
TextStyle(fontSize: 20, color: Colors.deepOrange))
working demo
full code
import 'package:flutter/material.dart';
import 'package:flutter_countdown_timer/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> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CountdownTimer(
endTime: 1594829147719,
defaultDays: "==",
defaultHours: "--",
defaultMin: "**",
defaultSec: "++",
daysSymbol: "days",
hoursSymbol: "hrs ",
minSymbol: "min ",
secSymbol: "sec",
daysTextStyle: TextStyle(fontSize: 30, color: Colors.red),
hoursTextStyle: TextStyle(fontSize: 30, color: Colors.orange),
minTextStyle: TextStyle(fontSize: 30, color: Colors.lightBlue),
secTextStyle: TextStyle(fontSize: 30, color: Colors.pink),
daysSymbolTextStyle:
TextStyle(fontSize: 20, color: Colors.green),
hoursSymbolTextStyle:
TextStyle(fontSize: 20, color: Colors.amberAccent),
minSymbolTextStyle:
TextStyle(fontSize: 20, color: Colors.black),
secSymbolTextStyle:
TextStyle(fontSize: 20, color: Colors.deepOrange)),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
Upvotes: 5