Skip to content

Commit

Permalink
docs(flutter_weather): update tutorial (#2519)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathankao97 committed Jun 17, 2021
1 parent c29f40e commit f9a4de9
Show file tree
Hide file tree
Showing 97 changed files with 2,151 additions and 3,565 deletions.
2 changes: 1 addition & 1 deletion docs/_sidebar.md
Expand Up @@ -18,7 +18,7 @@
- [Timer](fluttertimertutorial.md)
- [Infinite List](flutterinfinitelisttutorial.md)
- [**Login** <sup>✨</sup>](flutterlogintutorial.md)
- [Weather](flutterweathertutorial.md)
- [**Weather** <sup>✨</sup>](flutterweathertutorial.md)
- [Todos](fluttertodostutorial.md)
- [**Firebase Login** <sup>✨</sup>](flutterfirebaselogintutorial.md)
- [Firestore Todos](flutterfirestoretodostutorial.md)
Expand Down
19 changes: 0 additions & 19 deletions docs/_snippets/flutter_weather_tutorial/add_completer.dart.md

This file was deleted.

21 changes: 0 additions & 21 deletions docs/_snippets/flutter_weather_tutorial/app.dart.md

This file was deleted.

26 changes: 0 additions & 26 deletions docs/_snippets/flutter_weather_tutorial/app2.dart.md

This file was deleted.

This file was deleted.

@@ -0,0 +1,3 @@
```sh
flutter packages pub run build_runner build
```
@@ -0,0 +1,7 @@
```
flutter_weather
|-- lib/
|-- theme/
|-- cubit/
|-- theme_cubit.dart
```
@@ -0,0 +1,8 @@
```
flutter_weather
|-- lib/
|-- weather/
|-- cubit/
|-- weather_cubit.dart
|-- weather_state.dart
```
45 changes: 0 additions & 45 deletions docs/_snippets/flutter_weather_tutorial/city_selection.dart.md

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,5 @@
```dart
library meta_weather_api;
export 'src/models/models.dart';
```
@@ -0,0 +1,3 @@
```sh
flutter create --template=package meta_weather_api
```
@@ -0,0 +1,21 @@
```dart
/// Fetches [Weather] for a given [locationId].
Future<Weather> getWeather(int locationId) async {
final weatherRequest = Uri.https(_baseUrl, '/api/location/$locationId');
final weatherResponse = await _httpClient.get(weatherRequest);
if (weatherResponse.statusCode != 200) {
throw WeatherRequestFailure();
}
final weatherJson = jsonDecode(
weatherResponse.body,
)['consolidated_weather'] as List;
if (weatherJson.isEmpty) {
throw WeatherRequestFailure();
}
return Weather.fromJson(weatherJson.first as Map<String, dynamic>);
}
```
@@ -0,0 +1,17 @@
```yaml
name: meta_weather_api
description: A Dart API Client for the MetaWeather API.
version: 1.0.0+1

environment:
sdk: ">=2.12.0 <3.0.0"

dependencies:
http: ^0.13.0
json_annotation: ^4.0.0

dev_dependencies:
coverage: ^0.14.1
build_runner: ^1.10.0
json_serializable: ^4.0.0
```
@@ -0,0 +1,15 @@
```yaml
name: meta_weather_api
description: A Dart API Client for the MetaWeather API.
version: 1.0.0+1

environment:
sdk: ">=2.12.0 <3.0.0"

dependencies:
json_annotation: ^4.0.0

dev_dependencies:
build_runner: ^1.10.0
json_serializable: ^4.0.0
```
@@ -0,0 +1,31 @@
```dart
enum LocationType {
city,
region,
state,
province,
country,
continent
}
class Location {
const Location({
required this.title,
required this.locationType,
required this.latLng,
required this.woeid,
});
final String title;
final LocationType locationType;
final LatLng latLng;
final int woeid;
}
class LatLng {
const LatLng({required this.latitude, required this.longitude});
final double latitude;
final double longitude;
}
```
@@ -0,0 +1,8 @@
```json
{
"title": "London",
"location_type": "City",
"woeid": 44418,
"latt_long": "51.506321,-0.12714"
}
```
@@ -0,0 +1,25 @@
```dart
/// Finds a [Location] `/api/location/search/?query=(query)`.
Future<Location> locationSearch(String query) async {
final locationRequest = Uri.https(
_baseUrl,
'/api/location/search',
<String, String>{'query': query},
);
final locationResponse = await _httpClient.get(locationRequest);
if (locationResponse.statusCode != 200) {
throw LocationIdRequestFailure();
}
final locationJson = jsonDecode(
locationResponse.body,
) as List;
if (locationJson.isEmpty) {
throw LocationIdRequestFailure();
}
return Location.fromJson(locationJson.first as Map<String, dynamic>);
}
```
@@ -0,0 +1,18 @@
```
flutter_weather
|-- lib/
|-- test/
|-- packages/
|-- meta_weather_api/
|-- lib/
|-- src/
|-- models/
|-- location.dart
|-- location.g.dart
|-- weather.dart
|-- weather.g.dart
|-- models.dart
|-- meta_weather_api_client.dart
|-- meta_weather_api.dart
|-- test/
```

0 comments on commit f9a4de9

Please sign in to comment.