Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SpecificLaunch extends StatefulWidget {
- final String heroTag;
- SpecificLaunch({this.heroTag});
- @override
- _SpecificLaunchState createState() => _SpecificLaunchState();
- }
- class _SpecificLaunchState extends State<SpecificLaunch> {
- @override
- void dispose() {
- timer.cancel();
- super.dispose();
- }
- static const duration = const Duration(seconds: 1);
- int timeDiff = DateTime.parse(launchesObject.launchDate)
- .difference(DateTime.now())
- .inSeconds;
- bool isActive = true;
- Timer timer;
- @override
- Widget build(BuildContext context) {
- if (timer == null) {
- timer = Timer.periodic(duration, (Timer t) {
- if (timeDiff > 0) {
- setState(() {
- if (mounted) if (DateTime.parse(launchesObject.launchDate) !=
- DateTime.now()) {
- timeDiff -= 1;
- } else {
- print('Times up!');
- //Do something
- }
- });
- }
- });
- }
- int days = timeDiff ~/ (24 * 60 * 60);
- int hours = timeDiff ~/ (60 * 60) % 24;
- int minutes = (timeDiff ~/ 60) % 60;
- int seconds = timeDiff % 60;
- return DefaultTabController(
- length: 3,
- child: Scaffold(
- appBar: AppBar(
- title: Text(
- 'Launch',
- style: GoogleFonts.poppins(fontWeight: FontWeight.w600),
- ),
- actions: [
- IconButton(icon: Icon(Icons.share_outlined), onPressed: () {})
- ],
- ),
- body: Padding(
- padding: EdgeInsets.only(
- top: getHeight(context) / 30.0,
- left: getWidth(context) / 30.0,
- right: getWidth(context) / 30.0),
- child: Column(
- children: [
- Container(
- height: getHeight(context) / 3.5,
- width: getWidth(context),
- child: Card(
- shape: RoundedRectangleBorder(
- borderRadius:
- BorderRadius.circular(getWidth(context) / 36.0)),
- child: Stack(
- children: [
- Container(
- height: getHeight(context),
- width: getWidth(context),
- child: Hero(
- tag: widget.heroTag,
- child: CachedNetworkImage(
- imageUrl: launchesObject.launchImageUrl,
- fit: BoxFit.cover,
- placeholder: (context, url) {
- return Container();
- },
- ),
- ),
- ),
- Align(
- alignment: Alignment.bottomCenter,
- child: Container(
- height: getHeight(context) / 13.0,
- width: getWidth(context),
- color:
- SpecificColors(context).timerBackgroundColor,
- alignment: Alignment.center,
- child: Text(
- days.toString() +
- 'dd ' +
- hours.toString() +
- 'h ' +
- minutes.toString() +
- 'm ' +
- seconds.toString() +
- 's',
- style: GoogleFonts.poppins(
- fontWeight: FontWeight.w500,
- fontSize: 22,
- color:
- SpecificColors(context).timerTextColor),
- ),
- ),
- )
- ],
- ),
- ),
- ),
- Container(
- height: 70,
- child: AppBar(
- centerTitle: true,
- title: Text("New Titile"),
- bottom: TabBar(
- tabs: [
- Tab(
- text: 'State',
- ),
- Tab(
- text: 'Mission',
- ),
- Tab(
- text: 'Rocket',
- )
- ],
- ),
- ),
- ),
- Expanded(
- child: TabBarView(
- children: [
- Text(
- 'Tab 1',
- ),
- Text('Tab 2'),
- Text('Tab 3')
- ],
- ),
- )
- ],
- ),
- )),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement