Skip to content

Commit

Permalink
feat: fake realtime weather (#8)
Browse files Browse the repository at this point in the history
* feat: WeatherRepository

* feat: fake realtime weather

* refactor: extracted weather to own folder

* removed unnecessary Positioned and key

* refactor: changed structure

* added packages workflows

* fix: comment and bootstrap
  • Loading branch information
jneschisi authored Aug 1, 2024
1 parent 9e8a6cd commit cb50df3
Show file tree
Hide file tree
Showing 51 changed files with 1,219 additions and 314 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/weather_api_client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: weather_api_client

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
paths:
- "packages/weather_api_client/**"
- ".github/workflows/weather_api_client.yaml"
branches:
- main

jobs:
build:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1
with:
working_directory: packages/weather_api_client
19 changes: 19 additions & 0 deletions .github/workflows/weather_repository.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: weather_repository

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
paths:
- "packages/weather_repository/**"
- ".github/workflows/weather_repository.yaml"
branches:
- main

jobs:
build:
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1
with:
working_directory: packages/weather_repository
Binary file removed assets/thunder.png
Binary file not shown.
Binary file added assets/weather/clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/weather/cloudy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/weather/rainy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/weather/thunderstorms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 20 additions & 5 deletions lib/app/view/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,34 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:just_audio/just_audio.dart';
import 'package:music_repository/music_repository.dart';
import 'package:weather_repository/weather_repository.dart';

class App extends StatelessWidget {
const App({super.key});
const App({
required WeatherRepository weatherRepository,
required MusicRepository musicRepository,
required AudioPlayer audioPlayer,
super.key,
}) : _weatherRepository = weatherRepository,
_musicRepository = musicRepository,
_audioPlayer = audioPlayer;

final WeatherRepository _weatherRepository;
final MusicRepository _musicRepository;
final AudioPlayer _audioPlayer;

@override
Widget build(BuildContext context) {
return MultiRepositoryProvider(
providers: [
RepositoryProvider(
create: (context) => MusicRepository(),
RepositoryProvider.value(
value: _weatherRepository,
),
RepositoryProvider.value(
value: _musicRepository,
),
RepositoryProvider(
create: (context) => AudioPlayer(),
RepositoryProvider.value(
value: _audioPlayer,
),
],
child: AesLayout(
Expand Down
1 change: 1 addition & 0 deletions lib/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ Future<void> bootstrap(FutureOr<Widget> Function() builder) async {

// Add cross-flavor configuration here

WidgetsFlutterBinding.ensureInitialized();
runApp(await builder());
}
30 changes: 29 additions & 1 deletion lib/generated/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,24 @@
"welcomeMessage": "Welcome on board",
"welcomeSubtitle": "Lunch will be served in\n10 minutes",
"assistButton": "ASSIST",
"thunderstorms": "Thunderstorms"
"clear": "Clear",
"@clear": {
"description": "The label shown when weather is clear."
},
"cloudy": "Cloudy",
"@cloudy": {
"description": "The label shown when weather is cloudy."
},
"rainy": "Rainy",
"@rainy": {
"description": "The label shown when weather is rainy."
},
"thunderstorms": "Thunderstorms",
"@thunderstorms": {
"description": "The label shown when weather is thunderstorms."
},
"weatherErrorMessage": "Uh oh! There was an error while fetching the weather information.",
"@weatherErrorMessage": {
"description": "The error message for when the weather information fails to update."
}
}
16 changes: 15 additions & 1 deletion lib/main_development.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import 'package:airplane_entertainment_system/app/app.dart';
import 'package:airplane_entertainment_system/bootstrap.dart';
import 'package:just_audio/just_audio.dart';
import 'package:music_repository/music_repository.dart';
import 'package:weather_api_client/weather_api_client.dart';
import 'package:weather_repository/weather_repository.dart';

void main() {
bootstrap(() => const App());
bootstrap(() {
final weatherRepository = WeatherRepository(WeatherApiClient());
final musicRepository = MusicRepository();
final audioPlayer = AudioPlayer();

return App(
weatherRepository: weatherRepository,
musicRepository: musicRepository,
audioPlayer: audioPlayer,
);
});
}
16 changes: 15 additions & 1 deletion lib/main_production.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import 'package:airplane_entertainment_system/app/app.dart';
import 'package:airplane_entertainment_system/bootstrap.dart';
import 'package:just_audio/just_audio.dart';
import 'package:music_repository/music_repository.dart';
import 'package:weather_api_client/weather_api_client.dart';
import 'package:weather_repository/weather_repository.dart';

void main() {
bootstrap(() => const App());
bootstrap(() {
final weatherRepository = WeatherRepository(WeatherApiClient());
final musicRepository = MusicRepository();
final audioPlayer = AudioPlayer();

return App(
weatherRepository: weatherRepository,
musicRepository: musicRepository,
audioPlayer: audioPlayer,
);
});
}
16 changes: 15 additions & 1 deletion lib/main_staging.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import 'package:airplane_entertainment_system/app/app.dart';
import 'package:airplane_entertainment_system/bootstrap.dart';
import 'package:just_audio/just_audio.dart';
import 'package:music_repository/music_repository.dart';
import 'package:weather_api_client/weather_api_client.dart';
import 'package:weather_repository/weather_repository.dart';

void main() {
bootstrap(() => const App());
bootstrap(() {
final weatherRepository = WeatherRepository(WeatherApiClient());
final musicRepository = MusicRepository();
final audioPlayer = AudioPlayer();

return App(
weatherRepository: weatherRepository,
musicRepository: musicRepository,
audioPlayer: audioPlayer,
);
});
}
1 change: 1 addition & 0 deletions lib/overview/view/overview_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:aes_ui/aes_ui.dart';
import 'package:airplane_entertainment_system/l10n/l10n.dart';
import 'package:airplane_entertainment_system/overview/overview.dart';
import 'package:airplane_entertainment_system/weather/weather.dart';
import 'package:flutter/material.dart';

class OverviewPage extends StatelessWidget {
Expand Down
106 changes: 0 additions & 106 deletions lib/overview/widgets/weather_card.dart

This file was deleted.

1 change: 0 additions & 1 deletion lib/overview/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export 'airplane_image.dart';
export 'flight_tracking_card.dart';
export 'movie_card.dart';
export 'music_card.dart';
export 'weather_card.dart';
37 changes: 37 additions & 0 deletions lib/weather/bloc/weather_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:weather_repository/weather_repository.dart';

part 'weather_event.dart';
part 'weather_state.dart';

class WeatherBloc extends Bloc<WeatherEvent, WeatherState> {
WeatherBloc({
required WeatherRepository weatherRepository,
}) : _weatherRepository = weatherRepository,
super(const WeatherState()) {
on<WeatherUpdatesRequested>(_onWeatherUpdatesRequested);
}

final WeatherRepository _weatherRepository;

Future<void> _onWeatherUpdatesRequested(
WeatherUpdatesRequested event,
Emitter<WeatherState> emit,
) async {
await emit.forEach(
_weatherRepository.weatherInformation,
onData: (weatherInfo) {
return state.copyWith(
weatherInfo: weatherInfo,
status: WeatherStatus.updating,
);
},
onError: (error, stackTrace) {
return state.copyWith(status: WeatherStatus.error);
},
);
}
}
Loading

0 comments on commit cb50df3

Please sign in to comment.