set_title_handler.dart 692 Bytes
import 'package:appframe/bloc/web_cubit.dart';
import 'package:appframe/services/dispatcher.dart';

class SetTitleHandler extends MessageHandler {
  late WebCubit? _webCubit;

  @override
  void setCubit(WebCubit cubit) {
    this._webCubit = cubit;
  }

  void _unfollowCubit() {
    this._webCubit = null;
  }

  @override
  Future<dynamic> handleMessage(params) async {
    try {
      if (params is! Map<String, dynamic>) {
        throw Exception('参数错误');
      }

      final String title = params['title'] as String;
      final bool showBack = params['showBack'] as bool;

      return _webCubit!.setTitle(title, showBack);
    } finally {
      _unfollowCubit();
    }
  }
}