During the development, we need to be sure that everything works fine. So, we need to test our code. There are several testing stages and one of them is Unit Testing. In this article, we will write simple Bloc that will fetch and filter items. Then we will write test for our Bloc.
During the coding, we will need following dependencies. Add following to dependencies:
Equatable is used to simplify equality processes (In Dart if we compare to object using == it will not compare them with fields, will compare with hashcode and == operator. …
Sometimes we want to make our apps support dark mode. It is easy with Flutter, but reusable code and decoupling of presentation and business logic is an important topic. That is why I shall try to implement enable/disable dark mode and store the current state of theme using flutter_bloc library.
Make sure you have added all libraries correctly.
day_night_switcher is an optional. You can pass it and use simple Switch in Flutter.
We will store ThemeMode in SharedPreferences. If the value is true, dark mode is enabled, otherwise not.
Localization is one of the most important thing in mobile development. Flutter makes it easy for us, but we need to write our code more readable and decouple business logic and presentation. That’s why, I shall try to make localization using flutter_bloc library.
Make sure you have added libraries to your pubspec.yaml.
First of all, we should create SharedPreferencesService for storing user’s language selection. It seems like following:
It is optional part, you can pass it. I have created simple enum to simplfy language selection.
Create assets folder in your app level and inside it create langs…