Source code Click here to view the full source code of this example
Bloc is one of the most widely used libraries in the Flutter ecosystem, which is why we’ve included an example to demonstrate its integration.
Our example demonstrates how to provide a light/dark theme Cubit using Disco.
Dependency
This is the flutter_bloc
version used in this example:
File structure
Let’s look at the file structure:
Directorycubit
Directorydi
Directoryui
Directoryscreens
Directorywidgets
- main.dart
ThemeCubit
Let’s get started by writing a class that extends Cubit<bool>
.
Providers
In a separate file, we define the providers.
We also define a button where we inject the themeProvider
. We want it to display different texts based on the current value.
ThemeSwitcherPage
We define the page for our example. It contains a ThemedButton
.
App
Let’s finish the example by adding the following code in our main.dart
.