Search
 
SCRIPT & CODE EXAMPLE
 

DART

bloc to bloc communication in flutter

class MyWidget extends StatelessWidget {
  const MyWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocListener<WeatherCubit, WeatherState>(
      listener: (context, state) {
        // When the first bloc's state changes, this will be called.
        //
        // Now we can add an event to the second bloc without it having
        // to know about the first bloc.
        BlocProvider.of<SecondBloc>(context).add(SecondBlocEvent());
      },
      child: TextButton(
        child: const Text('Hello'),
        onPressed: () {
          BlocProvider.of<FirstBloc>(context).add(FirstBlocEvent());
        },
      ),
    );
  }
}
Comment

bloc to bloc communication in flutter

class MyWidget extends StatelessWidget {
  const MyWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocListener<WeatherCubit, WeatherState>(
      listener: (context, state) {
        // When the first bloc's state changes, this will be called.
        //
        // Now we can add an event to the second bloc without it having
        // to know about the first bloc.
        BlocProvider.of<SecondBloc>(context).add(SecondBlocEvent());
      },
      child: TextButton(
        child: const Text('Hello'),
        onPressed: () {
          BlocProvider.of<FirstBloc>(context).add(FirstBlocEvent());
        },
      ),
    );
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: how to create camera icon in flutter dev 
Dart :: scrolling to top sliverlist flutter with back button 
Dart :: dart test matcher expecting a field value 
Dart :: flutter sidebox 
Dart :: create array in flutter 
Dart :: Single document from firestore to a dart object 
Dart :: dart async map 
Dart :: a function body must be provided flutter 
Dart :: a function body must be provided. try adding a function body. flutter 
Dart :: dart list join 
Dart :: how to group data by date in a listview in flutter 
Dart :: dart code examples 
Swift :: delay code execution swift 5 
Swift :: Split a String into an array in Swift 
Swift :: swift ui square root 
Swift :: get device name swift 
Swift :: remove checkmark when selecting the cell again swift 5 
Swift :: quartzcore framework pi chart 
Swift :: swift get top constraint 
Swift :: alamofire failure response body 
Swift :: swiftui text field 
Swift :: swift alamofire x-www-form-urlencoded 
Swift :: how to change background color of ui button swift 
Swift :: porsche 
Swift :: most frequent element in array swift 
Swift :: how to low case string swift 
Swift :: white status bar swift 
Swift :: swiftui crop image 
Swift :: Swift Markup in Xcode 11 
Swift :: view will appear 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =