1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| class BlocConsumerr extends StatelessWidget { @override Widget build(BuildContext context) { return BlocProvider( create: (BuildContext context) { return TTBloc(TTInitState()); }, child: BlocConsumer<TTBloc, TTState>( listener: (BuildContext context, TTState state) { print("lyll BlocConsumerr listener ${state.runtimeType}"); }, listenWhen: (previous, current) { print( "lyll BlocConsumerr listenWhen ${previous.runtimeType} ${current.runtimeType}"); return true; }, buildWhen: (previous, current) { print( "lyll BlocConsumerr buildWhen ${previous.runtimeType} ${current.runtimeType}"); return true; }, builder: (BuildContext ctx, TTState state) { if (state is TTInitState) { ctx.read<TTBloc>().add(TTRequestEvent()); } else if (state is TTClickSuccessState) {} return Container( width: 300, height: 300, color: Colors.cyan, child: Center( child: GestureDetector( onTap: () { print("lyll BlocConsumerr TTClickEvent"); ctx.read<TTBloc>().add(TTClickEvent()); }, child: Container( width: 100, height: 100, color: Colors.amberAccent, ), ), ), ); }, ), ); } }
|