Skip to content

Instantly share code, notes, and snippets.

@demolaf
Created September 6, 2023 14:14
Show Gist options
  • Save demolaf/18ba396f1c3048bae58765cdd216fb82 to your computer and use it in GitHub Desktop.
Save demolaf/18ba396f1c3048bae58765cdd216fb82 to your computer and use it in GitHub Desktop.
glistening-snowflake-6186

glistening-snowflake-6186

Created with <3 with dartpad.dev.

// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const Countdown(),
);
}
}
class Countdown extends StatefulWidget {
const Countdown({super.key});
@override
State<Countdown> createState() => _CountdownState();
}
class _CountdownState extends State<Countdown> {
Duration getDuration() {
final DateTime now = DateTime.now();
final dateFromDB = DateTime.parse('2023-09-06T18:00:00');
return dateFromDB.difference(now);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: TweenAnimationBuilder<Duration>(
duration: getDuration(),
tween: Tween(
begin: getDuration(), end: Duration.zero),
onEnd: () {},
builder: (context, value, child) {
return Text(
value.toString().split('.')[0],
);
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment