Skip to content
This repository has been archived by the owner on Sep 14, 2024. It is now read-only.

Commit

Permalink
tighten our static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
Leptopoda committed Apr 21, 2023
1 parent 5438b40 commit 5d77b39
Show file tree
Hide file tree
Showing 73 changed files with 1,379 additions and 1,472 deletions.
21 changes: 21 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,24 @@ include: package:lint/strict.yaml
linter:
rules:
sort_pub_dependencies: false
prefer_final_parameters: false
prefer_asserts_with_message: false
only_throw_errors: false

prefer_mixin: true
discarded_futures: true
unawaited_futures: true
prefer_expression_function_bodies: true
always_put_control_body_on_new_line: true
use_key_in_widget_constructors: true
always_put_required_named_parameters_first: true
prefer_single_quotes: true
sort_constructors_first: true
omit_local_variable_types: true
prefer_int_literals: true
cascade_invocations: true
avoid_equals_and_hash_code_on_mutable_classes: true
avoid_types_on_closure_parameters: true
use_decorated_box: true
unnecessary_lambdas: true
prefer_foreach: true
96 changes: 45 additions & 51 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down Expand Up @@ -42,19 +44,13 @@ void main() async {
MultiBlocProvider(
providers: [
BlocProvider<AuthenticationBloc>(
create: (context) {
return AuthenticationBloc()..add(const AppStarted());
},
create: (context) => AuthenticationBloc()..add(const AppStarted()),
),
BlocProvider<RecipesShortBloc>(
create: (context) {
return RecipesShortBloc();
},
create: (context) => RecipesShortBloc(),
),
BlocProvider<CategoriesBloc>(
create: (context) {
return CategoriesBloc();
},
create: (context) => CategoriesBloc(),
)
],
child: const App(),
Expand Down Expand Up @@ -87,51 +83,49 @@ class _AppState extends State<App> {
final savedLocalization = Settings.getValue<String>(
SettingKeys.language.name,
);
changeLocale(context, savedLocalization);
unawaited(changeLocale(context, savedLocalization));
}

@override
Widget build(BuildContext context) {
return ThemeModeHandler(
manager: ThemeModeManager(),
builder: (ThemeMode themeMode) => MaterialApp(
navigatorKey: IntentRepository().getNavigationKey(),
themeMode: themeMode,
theme: AppTheme.lightThemeData,
darkTheme: AppTheme.darkThemeData,
home: BlocConsumer<AuthenticationBloc, AuthenticationState>(
builder: (context, state) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
systemNavigationBarColor:
Theme.of(context).scaffoldBackgroundColor,
),
);
Widget build(BuildContext context) => ThemeModeHandler(
manager: ThemeModeManager(),
builder: (themeMode) => MaterialApp(
navigatorKey: IntentRepository().getNavigationKey(),
themeMode: themeMode,
theme: AppTheme.lightThemeData,
darkTheme: AppTheme.darkThemeData,
home: BlocConsumer<AuthenticationBloc, AuthenticationState>(
builder: (context, state) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
systemNavigationBarColor:
Theme.of(context).scaffoldBackgroundColor,
),
);

switch (state.status) {
case AuthenticationStatus.loading:
return const SplashPage();
case AuthenticationStatus.authenticated:
return const CategoryScreen();
case AuthenticationStatus.unauthenticated:
return const LoginScreen();
case AuthenticationStatus.invalid:
return const LoginScreen(
invalidCredentials: true,
);
case AuthenticationStatus.error:
return LoadingErrorScreen(message: state.error!);
}
},
listener: (context, state) async {
if (state.status != AuthenticationStatus.loading) {
FlutterNativeSplash.remove();
} else if (state.status == AuthenticationStatus.authenticated) {
await IntentRepository().handleIntent();
}
},
switch (state.status) {
case AuthenticationStatus.loading:
return const SplashPage();
case AuthenticationStatus.authenticated:
return const CategoryScreen();
case AuthenticationStatus.unauthenticated:
return const LoginScreen();
case AuthenticationStatus.invalid:
return const LoginScreen(
invalidCredentials: true,
);
case AuthenticationStatus.error:
return LoadingErrorScreen(message: state.error!);
}
},
listener: (context, state) async {
if (state.status != AuthenticationStatus.loading) {
FlutterNativeSplash.remove();
} else if (state.status == AuthenticationStatus.authenticated) {
await IntentRepository().handleIntent();
}
},
),
),
),
);
}
);
}
5 changes: 2 additions & 3 deletions lib/src/blocs/authentication/authentication_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ part 'authentication_state.dart';

class AuthenticationBloc
extends Bloc<AuthenticationEvent, AuthenticationState> {
final UserRepository userRepository = UserRepository();

AuthenticationBloc() : super(AuthenticationState()) {
on<AppStarted>(_mapAppStartedEventToState);
on<LoggedIn>(_mapLoggedInEventToState);
on<LoggedOut>(_mapLoggedOutEventToState);
}
final UserRepository userRepository = UserRepository();

Future<void> _mapAppStartedEventToState(
AppStarted event,
Emitter<AuthenticationState> emit,
) async {
final bool hasToken = await userRepository.hasAppAuthentication();
final hasToken = await userRepository.hasAppAuthentication();

if (hasToken) {
await userRepository.loadAppAuthentication();
Expand Down
3 changes: 1 addition & 2 deletions lib/src/blocs/authentication/authentication_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class AppStarted extends AuthenticationEvent {
}

class LoggedIn extends AuthenticationEvent {
final AppAuthentication appAuthentication;

const LoggedIn({required this.appAuthentication});
final AppAuthentication appAuthentication;

@override
List<Object> get props => [appAuthentication];
Expand Down
5 changes: 2 additions & 3 deletions lib/src/blocs/authentication/authentication_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ enum AuthenticationStatus {
}

class AuthenticationState extends Equatable {
final AuthenticationStatus status;
final String? error;

const AuthenticationState({
this.status = AuthenticationStatus.loading,
this.error,
}) : assert(
(status != AuthenticationStatus.error && error == null) ||
(status == AuthenticationStatus.error && error != null),
);
final AuthenticationStatus status;
final String? error;

@override
List<Object?> get props => [status, error];
Expand Down
3 changes: 1 addition & 2 deletions lib/src/blocs/categories/categories_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ part 'categories_event.dart';
part 'categories_state.dart';

class CategoriesBloc extends Bloc<CategoriesEvent, CategoriesState> {
final DataRepository dataRepository = DataRepository();

CategoriesBloc() : super(CategoriesState()) {
on<CategoriesLoaded>(_mapCategoriesLoadedEventToState);
}
final DataRepository dataRepository = DataRepository();

Future<void> _mapCategoriesLoadedEventToState(
CategoriesLoaded event,
Expand Down
9 changes: 4 additions & 5 deletions lib/src/blocs/categories/categories_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ enum CategoriesStatus {
}

class CategoriesState extends Equatable {
final CategoriesStatus status;
final String? error;
final Iterable<Category>? categories;
final Iterable<RecipeStub?>? recipes;

CategoriesState({
this.status = CategoriesStatus.loadInProgress,
this.error,
Expand All @@ -33,6 +28,10 @@ class CategoriesState extends Equatable {
assert(error != null && categories == null && recipes == null);
}
}
final CategoriesStatus status;
final String? error;
final Iterable<Category>? categories;
final Iterable<RecipeStub?>? recipes;

@override
List<Object?> get props => [status, error, categories];
Expand Down
5 changes: 2 additions & 3 deletions lib/src/blocs/login/login_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ part 'login_event.dart';
part 'login_state.dart';

class LoginBloc extends Bloc<LoginEvent, LoginState> {
final UserRepository userRepository = UserRepository();
final AuthenticationBloc authenticationBloc;

LoginBloc({
required this.authenticationBloc,
}) : super(LoginState()) {
on<LoginButtonPressed>(_mapLoginButtonPressedEventToState);
}
final UserRepository userRepository = UserRepository();
final AuthenticationBloc authenticationBloc;

Future<void> _mapLoginButtonPressedEventToState(
LoginButtonPressed event,
Expand Down
11 changes: 5 additions & 6 deletions lib/src/blocs/login/login_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ abstract class LoginEvent extends Equatable {
}

class LoginButtonPressed extends LoginEvent {
final String serverURL;
final String username;
final String originalBasicAuth;
final bool isAppPassword;
final bool isSelfSignedCertificate;

const LoginButtonPressed({
required this.serverURL,
required this.username,
required this.originalBasicAuth,
required this.isAppPassword,
required this.isSelfSignedCertificate,
});
final String serverURL;
final String username;
final String originalBasicAuth;
final bool isAppPassword;
final bool isSelfSignedCertificate;

@override
List<Object> get props =>
Expand Down
5 changes: 2 additions & 3 deletions lib/src/blocs/login/login_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ enum LoginStatus {
}

class LoginState extends Equatable {
final LoginStatus status;
final String? error;

const LoginState({
this.status = LoginStatus.initial,
this.error,
}) : assert(
(status != LoginStatus.failure && error == null) ||
(status == LoginStatus.failure && error != null),
);
final LoginStatus status;
final String? error;

@override
List<Object?> get props => [status, error];
Expand Down
3 changes: 1 addition & 2 deletions lib/src/blocs/recipe/recipe_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ part 'recipe_event.dart';
part 'recipe_state.dart';

class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
final DataRepository dataRepository = DataRepository();

RecipeBloc() : super(RecipeState()) {
on<RecipeLoaded>(_mapRecipeLoadedToState);
on<RecipeUpdated>(_mapRecipeUpdatedToState);
on<RecipeImported>(_mapRecipeImportedToState);
on<RecipeCreated>(_mapRecipeCreatedToState);
on<RecipeDeleted>(_mapRecipeDeletedToState);
}
final DataRepository dataRepository = DataRepository();

Future<void> _mapRecipeLoadedToState(
RecipeLoaded recipeLoaded,
Expand Down
15 changes: 5 additions & 10 deletions lib/src/blocs/recipe/recipe_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,40 @@ abstract class RecipeEvent extends Equatable {
}

class RecipeLoaded extends RecipeEvent {
final String recipeId;

const RecipeLoaded(this.recipeId);
final String recipeId;

@override
List<String> get props => [recipeId];
}

class RecipeUpdated extends RecipeEvent {
final Recipe recipe;

const RecipeUpdated(this.recipe);
final Recipe recipe;

@override
List<Object> get props => [recipe];
}

class RecipeCreated extends RecipeEvent {
final Recipe recipe;

const RecipeCreated(this.recipe);
final Recipe recipe;

@override
List<Object> get props => [recipe];
}

class RecipeImported extends RecipeEvent {
final String url;

const RecipeImported(this.url);
final String url;

@override
List<Object> get props => [url];
}

class RecipeDeleted extends RecipeEvent {
final Recipe recipe;

const RecipeDeleted(this.recipe);
final Recipe recipe;

@override
List<Object> get props => [recipe];
Expand Down
9 changes: 4 additions & 5 deletions lib/src/blocs/recipe/recipe_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ enum RecipeStatus {
}

class RecipeState extends Equatable {
final RecipeStatus status;
final String? error;
final Recipe? recipe;
final String? recipeId;

RecipeState({
this.status = RecipeStatus.loadInProgress,
this.error,
Expand Down Expand Up @@ -55,6 +50,10 @@ class RecipeState extends Equatable {
assert(error != null && recipe == null && recipeId == null);
}
}
final RecipeStatus status;
final String? error;
final Recipe? recipe;
final String? recipeId;

@override
List<Object?> get props => [status, error, recipe, recipeId];
Expand Down
Loading

0 comments on commit 5d77b39

Please sign in to comment.