123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import 'dart:async';
- import 'package:fis_ui/index.dart';
- import 'package:fis_ui/interface/interactive_container.dart';
- import 'package:flutter/material.dart';
- class FDelayedTiriggerButton extends FStatefulWidget {
- FDelayedTiriggerButton({
- Key? key,
- required this.child,
- required this.onPressed,
- required this.businessParent,
- required this.name,
- this.style,
- this.countdownSeconds,
- VoidCallback? onLongPress,
- ValueChanged<bool>? onHover,
- ValueChanged<bool>? onFocusChange,
- FocusNode? focusNode,
- bool autofocus = false,
- Clip clipBehavior = Clip.none,
- });
- FInteractiveContainer businessParent;
- String? name;
- double? countdownSeconds = 5;
- VoidCallback? onPressed;
- FWidget child;
- ButtonStyle? style;
- @override
- FState<FDelayedTiriggerButton> createState() => _FDelayElevatedButtonState();
- }
- class _FDelayElevatedButtonState extends FState<FDelayedTiriggerButton> {
- late double _countdownSeconds = widget.countdownSeconds ?? 5;
- Timer? _timer;
- @override
- void initState() {
- super.initState();
- startCountdown();
- }
- void startCountdown() {
- _timer = Timer.periodic(Duration(milliseconds: 100), (timer) {
- setState(() {
- if (_countdownSeconds > 0) {
- _countdownSeconds -= 0.1;
- } else {
- _timer?.cancel();
- }
- });
- });
- }
- @override
- void dispose() {
- _timer?.cancel();
- super.dispose();
- }
- @override
- FWidget build(BuildContext context) {
- return FContainer(
- child: FStack(
- children: [
- FElevatedButton(
- businessParent: widget.businessParent,
- name: 'FDelayedTiriggerButton',
- onPressed: _countdownSeconds > 0 ? null : widget.onPressed,
- child: widget.child,
- style: widget.style?.copyWith(
- textStyle: MaterialStateProperty.all(
- TextStyle(
- color: _countdownSeconds > 0 ? Colors.black : Colors.white,
- fontSize: 16,
- ),
- ),
- ),
- ),
- FPositioned(
- right: 4,
- top: 4,
- child: FContainer(
- width: 20,
- height: 20,
- child: FStack(
- children: [
- FCircularProgressIndicator(
-
- value: _countdownSeconds / (widget.countdownSeconds ?? 5),
- strokeWidth: 2.0,
- ),
- if (_countdownSeconds >= 0)
- FContainer(
- alignment: Alignment.topCenter,
- child: FRichText(
- text: TextSpan(
- text: (_countdownSeconds.toInt() + 1).toString(),
- style: TextStyle(
- color: Colors.black,
- fontSize: 14,
- height: 1.4,
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- ],
- ),
- );
- }
- }
|