timer_button 2.1.1 timer_button: ^2.1.1 copied to clipboard
Timer Button is a Flutter package that offers a customizable button widget capable of activation after a designated time interval.
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:timer_button/timer_button.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Timer Button Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
MyHomePageState createState() {
return MyHomePageState();
}
}
class MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Timer Button Demo'),
),
body: Material(
child: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
TimerButton(
label: "Try Again",
timeOutInSeconds: 5,
onPressed: () {
log("Time for some action!");
},
),
TimerButton(
label: "Outlined: Try Again",
timeOutInSeconds: 5,
onPressed: () {},
buttonType: ButtonType.outlinedButton,
disabledColor: Colors.deepOrange,
color: Colors.green,
activeTextStyle: const TextStyle(color: Colors.yellow),
disabledTextStyle: const TextStyle(color: Colors.pink),
),
TimerButton(
label: "Text: Try Again",
timeOutInSeconds: -5,
onPressed: () {
log("Time for some action!");
},
timeUpFlag: true,
buttonType: ButtonType.textButton,
disabledColor: Colors.deepOrange,
color: Colors.green,
),
TimerButton.builder(
builder: (context, timeLeft) {
return Text(
"Custom: $timeLeft",
style: const TextStyle(color: Colors.red),
);
},
onPressed: () {
log("Time for some action!");
},
timeOutInSeconds: 5,
),
],
),
),
),
),
);
}
}