Skip to content

Commit

Permalink
🚧 migrate to null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
toureholder committed Jun 14, 2021
1 parent f93ce68 commit 1ec21dd
Show file tree
Hide file tree
Showing 43 changed files with 422 additions and 432 deletions.
3 changes: 1 addition & 2 deletions lib/base/base_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart' as http;
import 'package:meta/meta.dart';

class BaseApi {
BaseApi({@required this.client});
BaseApi({required this.client});

final http.Client client;

Expand Down
56 changes: 56 additions & 0 deletions lib/base/dependencies.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_workshop/feature/home/home_bloc.dart';
import 'package:flutter_workshop/feature/login/login_bloc.dart';
import 'package:flutter_workshop/model/donation/donation.dart';
import 'package:flutter_workshop/model/donation/donation_api.dart';
import 'package:flutter_workshop/model/login/login_api.dart';
import 'package:flutter_workshop/model/login/login_response.dart';
import 'package:flutter_workshop/service/session.dart';
import 'package:flutter_workshop/service/shared_preferences_storage.dart';
import 'package:flutter_workshop/util/http_event.dart';
import 'package:http/http.dart' as http;
import 'package:provider/provider.dart';
import 'package:provider/single_child_widget.dart';
import 'package:shared_preferences/shared_preferences.dart';

Future<List<SingleChildWidget>> getDependencies() async {
final http.Client _httpClient = http.Client();

final SharedPreferences _sharedPreferences =
await SharedPreferences.getInstance();

final SharedPreferencesStorage _sharedPreferencesStorage =
SharedPreferencesStorage(_sharedPreferences);

final Session _session =
Session(diskStorageProvider: _sharedPreferencesStorage);

await SystemChrome.setPreferredOrientations(
[
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
);

return [
Provider<LoginBloc>(
create: (_) => LoginBloc(
controller: StreamController<HttpEvent<LoginResponse>>.broadcast(),
loginApi: LoginApi(client: _httpClient),
sessionProvider: _session,
),
),
Provider<HomeBloc?>(
create: (_) => HomeBloc(
controller: StreamController<List<Donation>>.broadcast(),
donationApi: DonationApi(client: _httpClient),
diskStorageProvider: _sharedPreferencesStorage,
sessionProvider: _session,
),
),
];
}
8 changes: 4 additions & 4 deletions lib/base/my_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import 'package:provider/single_child_widget.dart';

class MyApp extends StatefulWidget {
const MyApp({
Key key,
Key? key,
this.dependencies,
}) : super(key: key);

final List<SingleChildWidget> dependencies;
final List<SingleChildWidget>? dependencies;

@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
List<SingleChildWidget> _appDependencies;
List<SingleChildWidget>? _appDependencies;

@override
void initState() {
Expand All @@ -27,7 +27,7 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: _appDependencies,
providers: _appDependencies!,
child: BaseMaterialApp(),
);
}
Expand Down
17 changes: 9 additions & 8 deletions lib/config/l10n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class StringLocalizationsDelegate extends LocalizationsDelegate<L10n> {
this.testingLocale,
});

final Locale testingLocale;
final Locale? testingLocale;

@override
bool isSupported(Locale locale) =>
Expand All @@ -38,28 +38,29 @@ class L10n {
});

final Locale _locale;
final Locale testingLocale;
final Locale? testingLocale;
final String defaultLanguageCode = supportedLanguageCodes.first;
final Map<String, Map<String, String>> _localizedValues = Strings().map;

String _get(String key) {
if (_localizedValues[key] == null) return key;

final languageCode = testingLocale ?? _locale;
final languageCode = testingLocale?.languageCode ?? _locale.languageCode;

return _localizedValues[key][languageCode] ??
_localizedValues[key][defaultLanguageCode] ??
return _localizedValues[key]![languageCode] ??
_localizedValues[key]![defaultLanguageCode] ??
key;
}

static String getString(
static String? getString(
BuildContext context,
String key,
String? key,
) =>
key == null
? null
: Localizations.of<L10n>(
context,
L10n,
)._get(key);
)!
._get(key);
}
10 changes: 5 additions & 5 deletions lib/config/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import 'package:flutter_workshop/feature/login/login_bloc.dart';
import 'package:flutter_workshop/util/navigation.dart';
import 'package:provider/provider.dart';

MaterialPageRoute getRouteFactory(settings) {
MaterialPageRoute route;
MaterialPageRoute? getRouteFactory(settings) {
MaterialPageRoute? route;
switch (settings.name) {
case Home.routeName:
{
route = Navigation.makeRoute(Consumer<HomeBloc>(
builder: (context, bloc, child) => Home(bloc: bloc),
));
)) as MaterialPageRoute<dynamic>?;
}
break;

case Login.routeName:
{
route = Navigation.makeRoute(Consumer<LoginBloc>(
builder: (context, bloc, child) => Login(bloc: bloc),
));
)) as MaterialPageRoute<dynamic>?;
}
break;

Expand All @@ -31,7 +31,7 @@ MaterialPageRoute getRouteFactory(settings) {
final DetailArguments args = settings.arguments;
route = Navigation.makeRoute(Detail(
donation: args.donation,
));
)) as MaterialPageRoute<dynamic>?;
}
break;
}
Expand Down
16 changes: 7 additions & 9 deletions lib/custom/adaptive_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const double MEDUIM_SCREEN_MIN_WIDTH = 720;
const double LARGE_SCREEN_MIN_WIDTH = 1200;

class AdaptiveView extends StatelessWidget {
final Widget smallView;
final Widget mediumView;
final Widget largeView;
final FormFactor forcedFormFactor;
final Widget? smallView;
final Widget? mediumView;
final Widget? largeView;
final FormFactor? forcedFormFactor;

const AdaptiveView({
Key key,
Key? key,
this.smallView,
this.mediumView,
this.largeView,
Expand All @@ -23,7 +23,7 @@ class AdaptiveView extends StatelessWidget {
final formFactor =
forcedFormFactor ?? _getFormFactor(MediaQuery.of(context).size.width);

return _getView(formFactor);
return _getView(formFactor)!;
}

FormFactor _getFormFactor(double width) {
Expand All @@ -38,14 +38,12 @@ class AdaptiveView extends StatelessWidget {
return FormFactor.small;
}

Widget _getView(FormFactor formFactor) {
Widget? _getView(FormFactor formFactor) {
switch (formFactor) {
case FormFactor.large:
return largeView ?? mediumView ?? smallView;
break;
case FormFactor.medium:
return mediumView ?? largeView ?? smallView;
break;
default:
return smallView ?? mediumView ?? largeView;
}
Expand Down
16 changes: 8 additions & 8 deletions lib/custom/custom_alert_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter_workshop/config/platform_independent_constants.dart';

class CustomAlertDialog extends StatelessWidget {
const CustomAlertDialog({
Key key,
Key? key,
this.onConfirmed,
this.confirmationText,
this.cancellationText,
Expand All @@ -15,17 +15,17 @@ class CustomAlertDialog extends StatelessWidget {
this.hasCancelButton = false,
}) : super(key: key);

final VoidCallback onConfirmed;
final String confirmationText;
final String cancellationText;
final String titleText;
final String contentText;
final VoidCallback? onConfirmed;
final String? confirmationText;
final String? cancellationText;
final String? titleText;
final String? contentText;
final bool hasCancelButton;

@override
Widget build(BuildContext context) {
final Text title = titleText == null ? null : Text(titleText);
final Text content = contentText == null ? null : Text(contentText);
final Text? title = titleText == null ? null : Text(titleText!);
final Text? content = contentText == null ? null : Text(contentText!);

return AlertDialog(
title: title,
Expand Down
8 changes: 4 additions & 4 deletions lib/custom/custom_app_bar.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:flutter/material.dart';

class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
const CustomAppBar({Key key, this.actions, this.title}) : super(key: key);
const CustomAppBar({Key? key, this.actions, this.title}) : super(key: key);

final List<Widget> actions;
final String title;
final List<Widget>? actions;
final String? title;

@override
Widget build(BuildContext context) {
final String computedTitle = title == null ? '' : title;
final String computedTitle = title == null ? '' : title!;

return AppBar(
brightness: Brightness.light,
Expand Down
18 changes: 9 additions & 9 deletions lib/custom/custom_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ class PrimaryContainedButton extends StatelessWidget {
final VoidCallback onPressed;

const PrimaryContainedButton({
Key key,
@required this.child,
@required this.onPressed,
Key? key,
required this.child,
required this.onPressed,
}) : super(key: key);

@override
Expand All @@ -31,13 +31,13 @@ class PrimaryContainedButton extends StatelessWidget {
}

class PrimaryTextButton extends StatelessWidget {
final String text;
final VoidCallback onPressed;
final String? text;
final VoidCallback? onPressed;

const PrimaryTextButton({
Key key,
@required this.text,
@required this.onPressed,
Key? key,
required this.text,
required this.onPressed,
}) : super(key: key);

@override
Expand All @@ -55,7 +55,7 @@ class PrimaryTextButton extends StatelessWidget {
style: flatButtonStyle,
onPressed: onPressed,
child: Text(
text,
text!,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
Expand Down
Loading

0 comments on commit 1ec21dd

Please sign in to comment.