| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:trackoffical_app/logger.dart';
- import 'package:trackoffical_app/screen.dart';
- import '../../../generated/assets.dart';
- class DialogBase extends DialogBaseOffCount {
- const DialogBase({super.key, Duration? offAfter, required Widget child}) : super(
- offAfter: offAfter, child: child
- );
- @override
- State<StatefulWidget> createState() {
- return DialogBaseState();
- }
- }
- class DialogBaseState extends DialogBaseOffCountState<DialogBase> {
- @override
- Widget build(BuildContext context) {
- final style = (context.textTheme.titleLarge ?? const TextStyle())
- .copyWith(color: const Color(0xff333333), fontSize: 41.98.rpx);
- final children = <Widget>[
- Container(
- margin: EdgeInsets.only(left: 47.71.rpx, right: 47.71.rpx),
- padding:
- EdgeInsets.fromLTRB(5.85.wp, 9.67.wp, 5.85.wp, 9.67.wp),
- decoration: BoxDecoration(
- color: const Color(0xe6ffffff),
- borderRadius: BorderRadius.circular(17.18.rpx)),
- child: widget.child)
- ];
- if (widget.offAfter != null) {
- children.addAll([
- Obx(() => offCount(secondCount.value))
- ]);
- }
- return DefaultTextStyle(
- style: style,
- child: Container(
- width: context.width,
- height: context.height,
- color: const Color(0xB8000000),
- alignment: Alignment.center,
- child: Center(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: children,
- ),
- ),
- ));
- }
- }
- abstract class DialogBaseOffCount extends StatefulWidget{
- const DialogBaseOffCount({
- super.key,
- this.offAfter,
- required this.child});
- final Duration? offAfter;
- final Widget child;
- }
- abstract class DialogBaseOffCountState <T extends DialogBaseOffCount> extends State<T>{
- final Rx<int?> secondCount = Rx(null);
- Timer? _timer;
- DateTime _createAt = DateTime.now();
- var isActive = true;
- void onStop(){
- if(mounted){
- debug('back: ${widget.runtimeType}');
- Get.back();
- }
- }
- @override
- void initState() {
- super.initState();
- final offAfter = widget.offAfter;
- _createAt = DateTime.now();
- if (offAfter != null) {
- _timer = Timer.periodic(100.milliseconds, (timer) {
- final d = DateTime.now().difference(_createAt);
- secondCount.value =offAfter.inSeconds - (d.inMilliseconds / 1000).floor();
- if (d >= offAfter) {
- onStop();
- }
- });
- }
- }
- @override
- void dispose() {
- super.dispose();
- debug('${widget.runtimeType} dispose()');
- isActive = false;
- _timer?.cancel();
- }
- }
- Widget offCount(int? secondCount){
- return Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- SizedBox(height: 50.0.rpx),
- Text(
- secondCount?.toString() ?? '',
- style: TextStyle(fontSize: 150.0.rpx, color: const Color(0xffff870d)),
- )
- ],
- );
- }
- Widget dialogTitle(String title, Color titleColor, Widget content,
- {Duration? offAfter}) {
- return DialogBase(
- offAfter: offAfter,
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(title, style: TextStyle(color: titleColor, fontSize: 55.07.rpx, fontWeight: FontWeight.w700)),
- SizedBox(height: 32.1.rpx),
- content
- ],
- ),
- ) ;
- }
- Widget bean(int count, double fontSize) {
- return Row(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.end,
- children: [
- Image.asset(Assets.imagesIcBean, height: fontSize * 2.2, ),
- Text(
- ' X $count',
- style: TextStyle(color: const Color(0xffaaaaaa), fontSize: fontSize),
- )
- ],
- );
- }
|