2022-09-23 09:30:30 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class CustomMaterialButton extends StatelessWidget {
|
|
|
|
const CustomMaterialButton({
|
2023-11-11 13:07:32 +01:00
|
|
|
super.key,
|
2022-09-23 09:30:30 +02:00
|
|
|
required this.label,
|
|
|
|
this.isFilled = true,
|
|
|
|
this.isExpanded = false,
|
|
|
|
required this.onPressed,
|
2023-11-11 13:07:32 +01:00
|
|
|
});
|
2023-01-30 13:35:06 +01:00
|
|
|
final Widget label;
|
|
|
|
final bool isFilled;
|
|
|
|
final bool isExpanded;
|
|
|
|
final Function()? onPressed;
|
2022-09-23 09:30:30 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return TextButton(
|
|
|
|
style: ButtonStyle(
|
|
|
|
padding: MaterialStateProperty.all(
|
|
|
|
isExpanded
|
|
|
|
? const EdgeInsets.symmetric(horizontal: 24, vertical: 12)
|
|
|
|
: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
|
|
|
),
|
|
|
|
shape: MaterialStateProperty.all(
|
|
|
|
StadiumBorder(
|
|
|
|
side: isFilled
|
|
|
|
? BorderSide.none
|
|
|
|
: BorderSide(
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
backgroundColor: MaterialStateProperty.all(
|
|
|
|
isFilled ? Theme.of(context).colorScheme.primary : Colors.transparent,
|
|
|
|
),
|
|
|
|
foregroundColor: MaterialStateProperty.all(
|
|
|
|
isFilled
|
|
|
|
? Theme.of(context).colorScheme.surface
|
|
|
|
: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: onPressed,
|
|
|
|
child: label,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:33:27 +02:00
|
|
|
// ignore: must_be_immutable
|
2022-09-23 09:30:30 +02:00
|
|
|
class TimerButton extends StatefulWidget {
|
|
|
|
TimerButton({
|
2023-11-11 13:07:32 +01:00
|
|
|
super.key,
|
2022-09-23 09:30:30 +02:00
|
|
|
required this.seconds,
|
|
|
|
required this.isRunning,
|
|
|
|
required this.onTimerEnd,
|
|
|
|
this.label = const Text(''),
|
|
|
|
this.isFilled = true,
|
2023-11-11 13:07:32 +01:00
|
|
|
});
|
2023-01-30 13:35:06 +01:00
|
|
|
Widget label;
|
|
|
|
bool isFilled;
|
|
|
|
int seconds;
|
|
|
|
final bool isRunning;
|
|
|
|
final Function()? onTimerEnd;
|
2022-09-23 09:30:30 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<TimerButton> createState() => _TimerButtonState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _TimerButtonState extends State<TimerButton> {
|
|
|
|
void timer(int seconds) {
|
|
|
|
Future.delayed(const Duration(seconds: 1), () {
|
|
|
|
if (seconds > 0) {
|
|
|
|
setState(() {
|
|
|
|
seconds--;
|
|
|
|
});
|
|
|
|
timer(seconds);
|
|
|
|
} else {
|
|
|
|
widget.onTimerEnd!();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
//decrement seconds
|
|
|
|
if (widget.isRunning) {
|
|
|
|
timer(widget.seconds);
|
|
|
|
}
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext build) {
|
|
|
|
return TextButton(
|
|
|
|
style: ButtonStyle(
|
|
|
|
shape: MaterialStateProperty.all(
|
|
|
|
StadiumBorder(
|
|
|
|
side: widget.isFilled
|
|
|
|
? BorderSide.none
|
|
|
|
: BorderSide(
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
backgroundColor: MaterialStateProperty.all(
|
|
|
|
widget.isFilled
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Colors.transparent,
|
|
|
|
),
|
|
|
|
foregroundColor: MaterialStateProperty.all(
|
|
|
|
widget.isFilled
|
|
|
|
? Theme.of(context).colorScheme.surface
|
|
|
|
: Theme.of(context).colorScheme.primary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: widget.isRunning ? null : widget.onTimerEnd,
|
|
|
|
child: Text(
|
|
|
|
widget.isRunning ? '${widget.seconds}' : 'Install',
|
2022-09-23 16:33:27 +02:00
|
|
|
style: const TextStyle(
|
2022-09-23 09:30:30 +02:00
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|