1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
-
- import 'dart:async';
-
- import 'package:farmer_client/utils/timer.dart';
- import 'package:flutter/widgets.dart';
- import 'package:get/get.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
-
- Widget countdown(int sec, void Function() onFinish) {
- var _countdown = Rx<int>(sec);
-
- late Timer _timer;
- _timer = setInterval((_) {
- if (_countdown.value <= 1) {
- _timer.cancel();
- onFinish();
- return;
- }
- _countdown.value -= 1;
- }, 1000);
-
- return Obx(
- () => GestureDetector(
- onTap: () {
- _timer.cancel();
- // return;
- // onFinish();
- },
- child: Container(
- width: 50.w,
- height: 30.h,
- alignment: const Alignment(0, 0),
- decoration: const BoxDecoration(
- borderRadius: BorderRadius.all(Radius.circular(20)),
- color: Color(0x77222222)),
- child: Text(
- _countdown.value.toString() + '跳过',
- style: TextStyle(
- fontSize: 13.sp,
- letterSpacing: 2,
- color: const Color(0xFFFFFFFF),
- ),
- ),
- ),
- ),
- );
- }
|