import 'package:bloc/bloc.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/services.dart'; import 'event.dart'; import 'state.dart'; class GamesBloc extends Bloc { late MethodChannel _methodChannel; GamesBloc() : super(GamesState().init()) { on(_init); on(_gotoGamePage); } void _init(InitEvent event, Emitter emit) async { emit(state.clone()); } void _gotoGamePage(GotoGamePageEvent event, Emitter emit) async { try { _methodChannel = const MethodChannel('wow_english/game_method_channel'); await _methodChannel.invokeMethod('openGamePage', { "gameId": event.gameId }); } on PlatformException catch (e) { debugPrint("Failed to go to native page: '${e.message}'."); } } }