New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(flutter_weather): update tutorial #2519
Conversation
docs/flutterweathertutorial.md
Outdated
|-- test/ | ||
``` | ||
|
||
Next, we will be use the same packages as in the `meta_weather_api` package. In addition, we will also use the `meta_weather_api` package which we just created. Update your `pubspec.yaml` to look like the following and run `flutter packages get` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next, we will be use the same packages as in the `meta_weather_api` package. In addition, we will also use the `meta_weather_api` package which we just created. Update your `pubspec.yaml` to look like the following and run `flutter packages get` | |
Next, we will be use the same packages as in the `meta_weather_api` package. In addition, we will also use the `meta_weather_api` package which we just created. Update your `pubspec.yaml` to look like the following and run `flutter pub get` |
|
||
?> **Note:** We are going to add some assets (icons for weather types) in our app, so we need to include the assets folder in the pubspec.yaml. Please go ahead and create an _assets_ folder in the root of the project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add this note back in?
docs/flutterweathertutorial.md
Outdated
|
||
### Theme Cubits | ||
|
||
Next, let's put together the HydratedCubit we will use to keep track of the theme of our app. The goal is to have the theme changed based on the current weather information. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next, let's put together the HydratedCubit we will use to keep track of the theme of our app. The goal is to have the theme changed based on the current weather information. | |
Next, let's put together the HydratedCubit we will use to keep track of the theme of our app. The goal is to have the theme change based on the current weather information. |
docs/flutterweathertutorial.md
Outdated
|-- theme_cubit.dart | ||
``` | ||
|
||
We will expose an `updateTheme(Weather? weather)` method, which will update the theme cubit depending on the weather condition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will expose an `updateTheme(Weather? weather)` method, which will update the theme cubit depending on the weather condition | |
We will expose an `updateTheme(Weather? weather)` method, which will update the Theme Cubit depending on the weather condition |
docs/flutterweathertutorial.md
Outdated
- If our weather states return correct `WeatherStatusX` values. [Here](https://github.com/felangel/bloc/blob/master/examples/flutter_weather/test/weather/cubit/weather_state_test.dart) is a completed test file | ||
- If our HydratedCubits respond to events properly and is able to convert fromJson and toJson | ||
|
||
In addition to using `Mocktail` for mocking and the standard testing library, it is also reccomended to use [bloc_test](https://pub.dev/packages/bloc_test) library. `bloc_test` allows us to easily prepare our blocs for testing, handle state changes, and check results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to using `Mocktail` for mocking and the standard testing library, it is also reccomended to use [bloc_test](https://pub.dev/packages/bloc_test) library. `bloc_test` allows us to easily prepare our blocs for testing, handle state changes, and check results. | |
In addition to using `Mocktail` for mocking and the standard testing library, it is also reccomended to use the [bloc_test](https://pub.dev/packages/bloc_test) library. `bloc_test` allows us to easily prepare our blocs for testing, handle state changes, and check results. |
docs/flutterweathertutorial.md
Outdated
|
||
### Weather Page | ||
|
||
With the core logic of our app put together, it's time to put together the UI! We will start with the weather page which uses `dependency injection` in order to provide cubits to widgets. This is accomplished using `BlocProvider` and `BlocConsumer`. These objects essentially inject our Cubits whenever widgets are (re)rendered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the core logic of our app put together, it's time to put together the UI! We will start with the weather page which uses `dependency injection` in order to provide cubits to widgets. This is accomplished using `BlocProvider` and `BlocConsumer`. These objects essentially inject our Cubits whenever widgets are (re)rendered. | |
With the core logic of our app put together, it's time to put together the UI! We will start with the weather page which uses `dependency injection` in order to provide cubits to widgets. This is accomplished using `BlocProvider` and `BlocConsumer`. These objects inject our Cubits whenever widgets are (re)rendered. |
docs/flutterweathertutorial.md
Outdated
} | ||
``` | ||
|
||
This page depends on `SettingsPage, SearchPage` widgets, which we will create next |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This page depends on `SettingsPage, SearchPage` widgets, which we will create next | |
This page depends on `SettingsPage, SearchPage` widgets, which we will create next. |
docs/flutterweathertutorial.md
Outdated
|
||
## Presentation Layer: Individual Weather Widgets | ||
|
||
We will next create the UI for our app. Each individual widget corresponds to a particular state our Cubits can be in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will next create the UI for our app. Each individual widget corresponds to a particular state our Cubits can be in. | |
Now we will create the UI for our app. Each individual widget corresponds to a particular state that our Cubits can be in. |
docs/flutterweathertutorial.md
Outdated
|
||
### WeatherPopulated | ||
|
||
Next, lets create the UI for when a city has actually been queried for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next, lets create the UI for when a city has actually been queried for. | |
Next, let's create the UI for when we query a city. |
docs/flutterweathertutorial.md
Outdated
|
||
## Presentation Layer: Views | ||
|
||
Let's glue the rest of our app together! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's glue the rest of our app together! | |
Let's put the rest of our app together! |
docs/flutterweathertutorial.md
Outdated
|
||
## Testing Our Widgets and Views | ||
|
||
In order to feel comfortable about our testing coverage, we should also test the widgets and view pages we have created. Again, we also reccomend using the `bloc_test` library for this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to feel comfortable about our testing coverage, we should also test the widgets and view pages we have created. Again, we also reccomend using the `bloc_test` library for this. | |
In order to feel confident about our testing coverage, we should also test the widgets and view pages we have created. Again, we recommend using the `bloc_test` library for this. |
docs/flutterweathertutorial.md
Outdated
|
||
[Here](https://github.com/felangel/bloc/tree/master/examples/flutter_weather/test) is an example test suite which includes widget tests, cubit tests, and view tests. | ||
|
||
## Putting it all together. Visually testing functionality |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Putting it all together. Visually testing functionality | |
## Putting it all together! |
docs/flutterweathertutorial.md
Outdated
|
||
[weather.dart](_snippets/flutter_weather_tutorial/settings_button.dart.md ':include') | ||
The completed file, put together, looks like this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The completed file, put together, looks like this | |
Put together, the completed file should look like this: |
docs/flutterweathertutorial.md
Outdated
|
||
### Unit Testing our Data Layer Models | ||
|
||
First, let's unit test our data models, `location` and `weather`. We should focus on insuring that they can represent our data, translate from and to JSON form, and handle edge cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, let's unit test our data models, `location` and `weather`. We should focus on insuring that they can represent our data, translate from and to JSON form, and handle edge cases. | |
First, let's unit test our data models, `location` and `weather`. We should focus on ensuring that they can represent our data, translate from and to JSON, and handle edge cases. |
docs/flutterweathertutorial.md
Outdated
|
||
First, let's unit test our data models, `location` and `weather`. We should focus on insuring that they can represent our data, translate from and to JSON form, and handle edge cases. | ||
|
||
First, add the Dart testing library to our `pubspec.yaml` and run `flutter pub get`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, add the Dart testing library to our `pubspec.yaml` and run `flutter pub get`. | |
Add the Dart testing library to our `pubspec.yaml` and run `flutter pub get`. |
docs/flutterweathertutorial.md
Outdated
|
||
## Repository Layer | ||
|
||
The goal of our repository layer is to create a wrapper for our data layer, and facilitate communication with the Bloc layer. In doing this, the rest of our code base depends only on functions exposed by our repository layer, instead of specific data provider implementations. This makes it easier for data providers to be switched out in the long run, and even converted into Flutter plugins/packages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of our repository layer is to create a wrapper for our data layer, and facilitate communication with the Bloc layer. In doing this, the rest of our code base depends only on functions exposed by our repository layer, instead of specific data provider implementations. This makes it easier for data providers to be switched out in the long run, and even converted into Flutter plugins/packages. | |
The goal of our repository layer is to create a wrapper for our data layer and facilitate communication with the Bloc layer. In doing this, the rest of our code base depends only on functions exposed by our repository layer, instead of specific data provider implementations. This makes it easier to switch out data providers later, or even convert them into individual Flutter plugins/packages. |
docs/flutterweathertutorial.md
Outdated
|
||
### Creating Our Weather Repository Models | ||
|
||
Update your directory structure to look like this. We will be creating a new `weather.dart` models file to contain only data we want to store, and another `models.dart` barrel file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update your directory structure to look like this. We will be creating a new `weather.dart` models file to contain only data we want to store, and another `models.dart` barrel file. | |
Update your directory structure to look like the below. We will create a new `weather.dart` models file to contain only data we want to store, and another `models.dart` barrel file. |
docs/flutterweathertutorial.md
Outdated
export 'weather.dart'; | ||
``` | ||
|
||
As we did in the previous section, run the following command to use `build_runner` to create our auto-generated models and factory methods. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we did in the previous section, run the following command to use `build_runner` to create our auto-generated models and factory methods. | |
As we did in the previous step, run the following command to use `build_runner` to create our auto-generated models and factory methods. |
docs/flutterweathertutorial.md
Outdated
} | ||
``` | ||
|
||
Lastly, update the barrel file we created previously and we are done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lastly, update the barrel file we created previously and we are done. | |
Lastly, update the barrel file we created previously, and we are done with this step! |
docs/flutterweathertutorial.md
Outdated
|
||
### Testing Our Weather Repository | ||
|
||
To test our Weather Repository, we will use the [Mocktail](https://github.com/felangel/mocktail) library. Using this library, we will create mocks and insure that our weather repository's `getWeather` method works as it should. This includes testing when the API client fails, and making sure the `Weather` object returned is correct when the API call is successful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test our Weather Repository, we will use the [Mocktail](https://github.com/felangel/mocktail) library. Using this library, we will create mocks and insure that our weather repository's `getWeather` method works as it should. This includes testing when the API client fails, and making sure the `Weather` object returned is correct when the API call is successful. | |
To test our Weather Repository, we will use the [Mocktail](https://github.com/felangel/mocktail) library. Using this library, we will create mocks and insure that our weather repository's `getWeather` method works as it should. This includes testing when the API client fails, and making sure the returned `Weather` object is correct when the API call is successful. |
docs/flutterweathertutorial.md
Outdated
|
||
## Business Logic Layer: Weather Model | ||
|
||
In this section, we're going to implement our third weather model - this time for the weather feature of our main app. Note that we haven't been implementing the exact same model each time. In the API client package, our weather model contained all the info returned by the API. In the repository client package, our weather model contained only the data we wish to display in our app, and in this weather model, we will bake temperature settings into the weather model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this section, we're going to implement our third weather model - this time for the weather feature of our main app. Note that we haven't been implementing the exact same model each time. In the API client package, our weather model contained all the info returned by the API. In the repository client package, our weather model contained only the data we wish to display in our app, and in this weather model, we will bake temperature settings into the weather model. | |
In this section, we're going to implement our third weather model - this time for the weather feature of our main app. The goal of this model is to keep track of weather data displayed by our app and app settings. | |
Note that we haven't been implementing the exact same model each time. In the API client package, our weather model contained all the info returned by the API. In the repository client package, our weather model contained only the data we wish to display in our app. In this weather model, we will bake temperature settings into the weather model. |
docs/flutterweathertutorial.md
Outdated
|
||
In this section, we're going to implement our third weather model - this time for the weather feature of our main app. Note that we haven't been implementing the exact same model each time. In the API client package, our weather model contained all the info returned by the API. In the repository client package, our weather model contained only the data we wish to display in our app, and in this weather model, we will bake temperature settings into the weather model. | ||
|
||
Before we get started, lets update our project level dependencies to import the packages we've created and also the serialization/deserialization dependencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before we get started, lets update our project level dependencies to import the packages we've created and also the serialization/deserialization dependencies. | |
Before we get started, let's update our project-level dependencies to import the packages we've created and the serialization/deserialization dependencies. |
docs/flutterweathertutorial.md
Outdated
- assets/ | ||
``` | ||
|
||
We will be working in the `weather` features app, in our main project library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will be working in the `weather` features app, in our main project library. | |
We will be working inside the `weather` features app, in our main project library. |
docs/flutterweathertutorial.md
Outdated
|-- weather.dart | ||
``` | ||
|
||
The goal of our weather model is to keep track of weather data displayed by our app and also to keep track of settings. To keep track of settings (celsius, farenheit), create the temperature model in `weather` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of our weather model is to keep track of weather data displayed by our app and also to keep track of settings. To keep track of settings (celsius, farenheit), create the temperature model in `weather` | |
To keep track of settings (celsius, farenheit), create the temperature model in `weather` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the first sentence up to the top of this section
docs/flutterweathertutorial.md
Outdated
} | ||
``` | ||
|
||
Lastly, to wrap this section up, run `build_runner` to create the auto generated file and methods, and also export our models in the barrel file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lastly, to wrap this section up, run `build_runner` to create the auto generated file and methods, and also export our models in the barrel file | |
To wrap this section up, run `build_runner` to create the auto generated file and methods, then export our models in the barrel file. |
docs/flutterweathertutorial.md
Outdated
|
||
## Business Logic Layer: Weather and Theme Cubits | ||
|
||
In this tutorial, we will use HydratedCubits for our Bloc layer. HydratedCubits are essentially Cubits that can persist state across sessions when used in conjunction with HydratedStorage. In short, our HydratedCubits will keep track of state and expose methods which can be used to mutate state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this tutorial, we will use HydratedCubits for our Bloc layer. HydratedCubits are essentially Cubits that can persist state across sessions when used in conjunction with HydratedStorage. In short, our HydratedCubits will keep track of state and expose methods which can be used to mutate state. | |
Now, we will use HydratedCubits for our Bloc layer to allow for theming. HydratedCubits are Cubits that can persist state across sessions when used in conjunction with HydratedStorage. In short, our HydratedCubits will keep track of state and expose methods which can be used to mutate state. |
docs/flutterweathertutorial.md
Outdated
} | ||
``` | ||
|
||
We will also need to keep track of what units (farenheit or celsius) our app is in. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will also need to keep track of what units (farenheit or celsius) our app is in. | |
We will also need to keep track of what units (Fahrenheit or Celsius) our app is using. |
docs/flutterweathertutorial.md
Outdated
|
||
### Weather Cubits | ||
|
||
Finally! It's time to put together our Weather Cubit. Our Weather Cubit will expose the following methods: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally! It's time to put together our Weather Cubit. Our Weather Cubit will expose the following methods: | |
It's time to put together our Weather Cubit which will expose the following methods: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀 🎉
Status
in development
Breaking Changes
no
Description
update flutter weather tutorial (closes #2357)
Type of Change