Skip to content

Commit a0c769b

Browse files
authored
refactor: upgrade to dart3 (fireship-io#21)
* chore: upgrade sdk and packages * fix: address lint warnings * fix: bootstrap app * fix: preload images * chore: rename `data_providers` to `api_client` * chore: rename `shared` to `app_core` * chore: rename `ui_toolkit` to `app_ui` * refactor: use patterns * ci: fix format * refactor: remove interfaces
1 parent 25af83f commit a0c769b

File tree

88 files changed

+813
-737
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+813
-737
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
run: flutter packages get
1515

1616
- name: Format
17-
run: flutter format --set-exit-if-changed lib test
17+
run: dart format --set-exit-if-changed lib test
1818

1919
- name: Analyze
2020
run: flutter analyze lib test

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ subprojects {
2525
project.evaluationDependsOn(':app')
2626
}
2727

28-
task clean(type: Delete) {
28+
tasks.register("clean", Delete) {
2929
delete rootProject.buildDir
3030
}

ios/Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $FirebaseSDKVersion = '8.3.0'
44

55
require 'yaml'
66

7-
pubspec = YAML.load_file(File.join('..', 'packages/data_providers/pubspec.yaml'))
7+
pubspec = YAML.load_file(File.join('..', 'packages/api_client/pubspec.yaml'))
88

99
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
1010
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

lib/about/view/about_view.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import 'package:app_ui/app_ui.dart';
12
import 'package:flutter/material.dart';
23
import 'package:quizapp/l10n/l10n.dart';
3-
import 'package:ui_toolkit/ui_toolkit.dart';
44

55
class AboutView extends StatelessWidget {
66
const AboutView({super.key});

lib/app/app_bloc_observer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:developer';
22

3-
import 'package:shared/shared.dart';
3+
import 'package:app_core/app_core.dart';
44

55
class AppBlocObserver extends BlocObserver {
66
@override

lib/app/app_bootstrap.dart

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
1-
import 'dart:async';
21
import 'dart:developer';
2+
import 'dart:isolate';
33

4-
import 'package:data_providers/data_providers.dart';
4+
import 'package:app_core/app_core.dart';
5+
import 'package:app_ui/app_ui.dart';
56
import 'package:flutter/foundation.dart';
67
import 'package:flutter/widgets.dart';
7-
import 'package:shared/shared.dart';
8-
import 'package:ui_toolkit/ui_toolkit.dart';
8+
import 'package:quizapp/app/app_bloc_observer.dart';
99

10-
Future<void> bootstrap(
11-
FutureOr<Widget> Function() appDelegate, {
12-
void Function(Object, StackTrace)? onZoneError,
13-
FlutterExceptionHandler? onFlutterError,
14-
BlocObserver? blocObserver,
15-
Future<FirebaseApp> Function()? firebaseApp,
10+
Future<void> bootstrap({
11+
required FutureOr<Widget> Function() builder,
12+
FutureOr<void> Function()? init,
1613
}) async {
17-
WidgetsFlutterBinding.ensureInitialized();
14+
await runZonedGuarded(
15+
() async {
16+
BindingBase.debugZoneErrorsAreFatal = true;
17+
WidgetsFlutterBinding.ensureInitialized();
18+
await init?.call();
1819

19-
FlutterError.onError = onFlutterError ??
20-
(details) {
20+
FlutterError.onError = (details) {
2121
log(details.exceptionAsString(), stackTrace: details.stack);
2222
};
23+
PlatformDispatcher.instance.onError = (error, stackTrace) {
24+
log(error.toString(), stackTrace: stackTrace);
25+
return true;
26+
};
27+
Isolate.current.addErrorListener(
28+
RawReceivePort((dynamic pair) async {
29+
final errorAndStackTrace = pair as List<dynamic>;
30+
final error = errorAndStackTrace.first;
31+
final rawStackTrace = errorAndStackTrace.last;
32+
final stackTrace = rawStackTrace is StackTrace
33+
? rawStackTrace
34+
: StackTrace.fromString(rawStackTrace.toString());
35+
log(error.toString(), stackTrace: stackTrace);
36+
}).sendPort,
37+
);
2338

24-
await (firebaseApp ?? Firebase.initializeApp)();
25-
26-
await Assets.covers.preload();
39+
Bloc.observer = AppBlocObserver();
2740

28-
if (blocObserver != null) {
29-
Bloc.observer = blocObserver;
30-
}
41+
await Assets.covers.preload();
3142

32-
return runZonedGuarded<void>(
33-
() async => runApp(await appDelegate()),
34-
onZoneError ??
35-
(error, stackTrace) => log(error.toString(), stackTrace: stackTrace),
43+
final app = await builder();
44+
runApp(app);
45+
},
46+
(error, stackTrace) => log(error.toString(), stackTrace: stackTrace),
3647
);
3748
}

lib/app/cubit/app_cubit.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import 'dart:async';
2-
3-
import 'package:shared/shared.dart';
1+
import 'package:app_core/app_core.dart';
42
import 'package:user_repository/user_repository.dart';
53

64
part 'app_state.dart';

lib/app/cubit/app_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension AppStatusExtensions on AppStatus {
1414
bool get isFailure => this == AppStatus.failure;
1515
}
1616

17-
class AppState extends Equatable {
17+
final class AppState extends Equatable {
1818
const AppState._({
1919
required this.status,
2020
this.user = User.none,

lib/app/view/app.dart

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:app_ui/app_ui.dart';
12
import 'package:flow_builder/flow_builder.dart';
23
import 'package:flutter/material.dart';
34
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -6,12 +7,11 @@ import 'package:quizapp/app/cubit/app_cubit.dart';
67
import 'package:quizapp/home/home.dart';
78
import 'package:quizapp/l10n/l10n.dart';
89
import 'package:quizapp/login/login.dart';
9-
import 'package:ui_toolkit/ui_toolkit.dart';
1010
import 'package:user_repository/user_repository.dart';
1111

12-
List<Page<void>> onGenerateAppPages(
12+
List<Page<dynamic>> onGenerateAppPages(
1313
AppStatus status,
14-
List<Page<void>> pages,
14+
List<Page<dynamic>> pages,
1515
) {
1616
if (status.isUnauthenticated) {
1717
return [LoginPage.page()];
@@ -24,8 +24,8 @@ List<Page<void>> onGenerateAppPages(
2424

2525
class App extends StatelessWidget {
2626
const App({
27-
super.key,
2827
required this.userRepository,
28+
super.key,
2929
});
3030

3131
final UserRepository userRepository;
@@ -56,18 +56,16 @@ class AppView extends StatelessWidget {
5656
],
5757
supportedLocales: AppLocalizations.supportedLocales,
5858
home: BlocListener<AppCubit, AppState>(
59+
listenWhen: (_, current) => current.isFailure,
5960
listener: (context, state) {
60-
if (state.isFailure) {
61-
final failure = state.failure;
62-
final l10n = context.l10n;
63-
if (failure is AuthUserChangesFailure) {
64-
context.showSnackBar(l10n.authFailureMessage);
65-
} else if (failure is SignOutFailure) {
66-
context.showSnackBar(l10n.signOutFailureMessage);
67-
} else {
68-
context.showSnackBar(l10n.unknownFailureMessage);
69-
}
70-
}
61+
final l10n = context.l10n;
62+
return switch (state.failure) {
63+
AuthUserChangesFailure() =>
64+
context.showSnackBar(l10n.authFailureMessage),
65+
SignOutFailure() =>
66+
context.showSnackBar(l10n.signOutFailureMessage),
67+
_ => context.showSnackBar(l10n.unknownFailureMessage),
68+
};
7169
},
7270
child: FlowBuilder(
7371
onGeneratePages: onGenerateAppPages,

lib/home/view/bottom_nav_bar.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
import 'package:app_core/app_core.dart';
2+
import 'package:app_ui/app_ui.dart';
13
import 'package:flutter/material.dart';
24
import 'package:quizapp/l10n/l10n.dart';
3-
import 'package:shared/shared.dart';
4-
import 'package:ui_toolkit/ui_toolkit.dart';
55

66
enum NavBarItem { topics, about, profile }
77

88
extension NavBarItemExtensions on NavBarItem {
99
bool get isTopics => this == NavBarItem.topics;
1010
}
1111

12-
class NavBarController extends PageController {
12+
final class NavBarController extends PageController {
1313
NavBarController({NavBarItem initialItem = NavBarItem.topics})
1414
: _notifier = ValueNotifier<NavBarItem>(initialItem),
1515
super(initialPage: initialItem.index) {

0 commit comments

Comments
 (0)