bloc.dart 2.26 KB
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:wow_english/common/extension/string_extension.dart';

import '../../../../route/route.dart';
import 'event.dart';
import 'state.dart';

abstract class BaseSectionBloc<E extends BaseSectionEvent,
    S extends BaseSectionState> extends Bloc<E, S> {
  BaseSectionBloc(super.initialState);

  bool isCompleteDialogShow = false;

  ///这里可以定义一些通用的逻辑
  void sectionComplete(final VoidCallback? nextSectionTap,
      {VoidCallback? againSectionTap, BuildContext? context}) {
    // 逻辑来标记步骤为已完成
    // 比如更新状态
    if (isCompleteDialogShow) {
      return;
    }
    isCompleteDialogShow = true;
    showDialog(
      context: context ?? AppRouter.context,
      barrierDismissible: false,
      barrierColor: Colors.black54,
      builder: (BuildContext context) {
        return AlertDialog(
          backgroundColor: Colors.transparent,
          content: SizedBox(
            width: double.infinity, // 宽度设置为无限,使其尽可能铺满屏幕
            height: MediaQuery.of(context).size.height * 0.6, // 高度设置为屏幕高度的60%
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween, // 图片之间分配空间
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: GestureDetector(
                    onTap: () {
                      popPage();
                      againSectionTap?.call();
                    },
                    child: Image.asset('section_finish_again'.assetPng),
                  ),
                ),
                Expanded(
                  flex: 2,
                  child: Image.asset('section_finish_steve'.assetPng),
                ),
                Expanded(
                  flex: 1,
                  child: GestureDetector(
                    onTap: () {
                      popPage();
                      nextSectionTap?.call();
                    },
                    child: Image.asset('section_finish_next'.assetPng),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    ).then((value) => isCompleteDialogShow = false);
  }
}