diff --git a/.github/workflows/lint-and-test-pr.yml b/.github/workflows/lint-and-test-pr.yml index 3247dc3..f2ef1cc 100644 --- a/.github/workflows/lint-and-test-pr.yml +++ b/.github/workflows/lint-and-test-pr.yml @@ -11,7 +11,6 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - uses: monterail/flutter-action@v1 with: diff --git a/lib/main.dart b/lib/main.dart index 489cbe2..28b1c34 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -8,12 +8,8 @@ import 'package:sentry_flutter/sentry_flutter.dart' hide SentryClient; import 'src/app.dart'; void main() async => runZonedGuarded( - () async { - await bootWithSentry(); - }, - (error, stackTrace) { - Sentry.captureException(error, stackTrace: stackTrace); - }, + () async => bootWithSentry(), + (error, stackTrace) => Sentry.captureException(error, stackTrace: stackTrace), ); Future boot() async { diff --git a/lib/src/modules/bloc_screen/bloc/counter_bloc.dart b/lib/src/modules/bloc_screen/bloc/counter_bloc.dart index b9a7f0f..e6edd36 100644 --- a/lib/src/modules/bloc_screen/bloc/counter_bloc.dart +++ b/lib/src/modules/bloc_screen/bloc/counter_bloc.dart @@ -11,11 +11,9 @@ class CounterBloc extends Bloc { on<_Increased>(_onIncreased); } - void _onIncreased(_Increased event, Emitter emit) { - emit(state.copyWith(value: state.value + 1)); - } + void _onIncreased(_Increased event, Emitter emit) => + emit(state.copyWith(value: state.value + 1)); - void _onDecreased(_Decreased event, Emitter emit) { - emit(state.copyWith(value: state.value - 1)); - } + void _onDecreased(_Decreased event, Emitter emit) => + emit(state.copyWith(value: state.value - 1)); } diff --git a/lib/src/modules/bloc_screen/view/bloc_screen.dart b/lib/src/modules/bloc_screen/view/bloc_screen.dart index 387016c..4a7018f 100644 --- a/lib/src/modules/bloc_screen/view/bloc_screen.dart +++ b/lib/src/modules/bloc_screen/view/bloc_screen.dart @@ -14,32 +14,31 @@ class BlocScreen extends StatelessWidget { body: BlocProvider( create: (context) => CounterBloc(), child: BlocBuilder( - builder: (context, state) { - return Center( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - FloatingActionButton( - heroTag: 'minusBtn', - onPressed: - () => context.read().add( - const CounterEvent.decreased(), - ), - child: const Icon(Icons.remove), - ), - Text('${state.value}'), - FloatingActionButton( - heroTag: 'plusBtn', - onPressed: - () => context.read().add( - const CounterEvent.increased(), - ), - child: const Icon(Icons.add), - ), - ], + builder: + (context, state) => Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + FloatingActionButton( + heroTag: 'minusBtn', + onPressed: + () => context.read().add( + const CounterEvent.decreased(), + ), + child: const Icon(Icons.remove), + ), + Text('${state.value}'), + FloatingActionButton( + heroTag: 'plusBtn', + onPressed: + () => context.read().add( + const CounterEvent.increased(), + ), + child: const Icon(Icons.add), + ), + ], + ), ), - ); - }, ), ), ); diff --git a/lib/src/modules/cubit_screen/view/cubit_screen.dart b/lib/src/modules/cubit_screen/view/cubit_screen.dart index a3677d2..dfcbc9b 100644 --- a/lib/src/modules/cubit_screen/view/cubit_screen.dart +++ b/lib/src/modules/cubit_screen/view/cubit_screen.dart @@ -14,26 +14,25 @@ class CubitScreen extends StatelessWidget { body: BlocProvider( create: (context) => CounterCubit(), child: BlocBuilder( - builder: (context, state) { - return Center( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - FloatingActionButton( - heroTag: 'minusBtn', - onPressed: () => context.read().decrement(), - child: const Icon(Icons.remove), - ), - Text('${state.value}'), - FloatingActionButton( - heroTag: 'plusBtn', - onPressed: () => context.read().increment(), - child: const Icon(Icons.add), - ), - ], + builder: + (context, state) => Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + FloatingActionButton( + heroTag: 'minusBtn', + onPressed: () => context.read().decrement(), + child: const Icon(Icons.remove), + ), + Text('${state.value}'), + FloatingActionButton( + heroTag: 'plusBtn', + onPressed: () => context.read().increment(), + child: const Icon(Icons.add), + ), + ], + ), ), - ); - }, ), ), ); diff --git a/lib/src/modules/main_screen/bloc/main_screen_bloc.dart b/lib/src/modules/main_screen/bloc/main_screen_bloc.dart index e967e21..e2a7358 100644 --- a/lib/src/modules/main_screen/bloc/main_screen_bloc.dart +++ b/lib/src/modules/main_screen/bloc/main_screen_bloc.dart @@ -37,7 +37,7 @@ class MainScreenBloc extends Bloc { Emitter emit, ) async { emit(const MainScreenState.loading()); - final user = User(pk: 1, firstName: 'Jan', lastName: 'Nowak'); + final user = const User(pk: 1, firstName: 'Jan', lastName: 'Nowak'); final result = await userRepository.saveUser('userKey', user); final _ = switch (result) { Success(value: final _) => emit(MainScreenState.loaded(user)), diff --git a/lib/src/modules/main_screen/view/main_screen.dart b/lib/src/modules/main_screen/view/main_screen.dart index bf13be7..a1d1d9b 100644 --- a/lib/src/modules/main_screen/view/main_screen.dart +++ b/lib/src/modules/main_screen/view/main_screen.dart @@ -15,88 +15,89 @@ class MainScreen extends StatelessWidget { Widget build(BuildContext context) => BlocProvider( create: (context) => - MainScreenBloc(userRepository: UserRepository())..add(InitEvent()), + MainScreenBloc(userRepository: UserRepository()) + ..add(const InitEvent()), child: Scaffold( body: Center( child: BlocBuilder( - builder: (context, state) { - return Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - AppLocalizations.of(context)!.appTitle, - style: Theme.of(context).textTheme.headlineSmall, - ), - const Text( - '${EnvironmentVariables.appName} ${EnvironmentVariables.appSuffix}', - style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), - ), - const SizedBox(height: 16), - state.when( - initial: - () => Column( - children: [const Text('-'), _actionButtons(context)], - ), - loading: () => const CircularProgressIndicator(), - loaded: - (user) => Column( - children: [ - Text( - user.getFullName(), - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, + builder: + (context, state) => Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + AppLocalizations.of(context)!.appTitle, + style: Theme.of(context).textTheme.headlineSmall, + ), + const Text( + '${EnvironmentVariables.appName} ${EnvironmentVariables.appSuffix}', + style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500), + ), + const SizedBox(height: 16), + state.when( + initial: + () => Column( + children: [const Text('-'), _actionButtons(context)], + ), + loading: () => const CircularProgressIndicator(), + loaded: + (user) => Column( + children: [ + Text( + user.getFullName(), + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), ), - ), - _actionButtons(context), - ], - ), - error: - (message) => Column( - children: [ - Text( - message.translatedError, - style: const TextStyle( - color: Colors.red, - fontWeight: FontWeight.bold, + _actionButtons(context), + ], + ), + error: + (message) => Column( + children: [ + Text( + message.translatedError, + style: const TextStyle( + color: Colors.red, + fontWeight: FontWeight.bold, + ), ), - ), - _actionButtons(context), - ], + _actionButtons(context), + ], + ), + ), + const SizedBox(height: 20), + TextButton.icon( + onPressed: + () => context.read().add( + const ReportSentryError(), + ), + icon: const Icon(Icons.error, color: Colors.red), + label: const Text('Report an error to Sentry'), + ), + const SizedBox(height: 20), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + TextButton( + onPressed: + () => + context.router.push(CubitRoute(title: 'Cubit')), + child: const Text('To Cubit screen'), ), - ), - const SizedBox(height: 20), - TextButton.icon( - onPressed: - () => context.read().add( - ReportSentryError(), + TextButton( + onPressed: + () => context.router.push(BlocRoute(title: 'BLoC')), + child: const Text('To BLoC screen'), ), - icon: const Icon(Icons.error, color: Colors.red), - label: const Text('Report an error to Sentry'), - ), - const SizedBox(height: 20), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - TextButton( - onPressed: - () => context.router.push(CubitRoute(title: 'Cubit')), - child: const Text('To Cubit screen'), - ), - TextButton( - onPressed: - () => context.router.push(BlocRoute(title: 'BLoC')), - child: const Text('To BLoC screen'), - ), - ], - ), - TextButton( - child: Text('Licences'), - onPressed: () => showLicensePage(context: context), - ), - ], - ); - }, + ], + ), + TextButton( + child: const Text('Licences'), + onPressed: () => showLicensePage(context: context), + ), + ], + ), ), ), ), @@ -106,12 +107,14 @@ class MainScreen extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ ElevatedButton( - onPressed: () => context.read().add(RemoveUserEvent()), + onPressed: + () => context.read().add(const RemoveUserEvent()), child: const Text('Remove'), ), const SizedBox(width: 16), ElevatedButton( - onPressed: () => context.read().add(AddUserEvent()), + onPressed: + () => context.read().add(const AddUserEvent()), child: const Text('Add'), ), ], diff --git a/lib/src/services/sembast.dart b/lib/src/services/sembast.dart index a65663a..aa85d78 100644 --- a/lib/src/services/sembast.dart +++ b/lib/src/services/sembast.dart @@ -14,7 +14,7 @@ Future setupSembast() async { _database = await databaseFactoryWeb.openDatabase(_databaseName); } else { final appDir = await getApplicationDocumentsDirectory(); - final dbPath = '${appDir.path}/databaseName'; + final dbPath = '${appDir.path}/$_databaseName'; _database = await databaseFactoryIo.openDatabase(dbPath); } } diff --git a/lints.yaml b/lints.yaml index 7cf5f7e..8614e6d 100644 --- a/lints.yaml +++ b/lints.yaml @@ -16,6 +16,7 @@ linter: - avoid_void_async - sort_constructors_first - unawaited_futures + - unnecessary_await_in_return - unnecessary_breaks - unnecessary_parenthesis - unnecessary_raw_strings @@ -25,11 +26,16 @@ linter: - use_named_constants # solve code review quarrels + - always_declare_return_types - avoid_escaping_inner_quotes + - avoid_unnecessary_containers - avoid_final_parameters - cascade_invocations + - prefer_const_constructors + - prefer_final_fields - prefer_final_locals - prefer_final_in_for_each - prefer_null_aware_method_calls + - prefer_expression_function_bodies - prefer_single_quotes - require_trailing_commas \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 502ef7e..44f496e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: A new Flutter project. # Prevent accidental publishing to pub.dev. publish_to: 'none' -version: 2.0.0+1 +version: 2.0.1+1 environment: sdk: ">=3.7.0 <4.0.0" diff --git a/test/src/services/sembast_test.dart b/test/src/services/sembast_test.dart index 5cda82a..68e75cc 100644 --- a/test/src/services/sembast_test.dart +++ b/test/src/services/sembast_test.dart @@ -19,7 +19,7 @@ void main() { group('Sembast Database with User model', () { const userKey = 'user1'; - final user = User( + final user = const User( pk: 1, email: 'test@example.com', phone: '123456789', diff --git a/test/widget_test.dart b/test/widget_test.dart index 574c5ed..7e66638 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -19,9 +19,7 @@ void main() { final myWidget = MaterialApp( localizationsDelegates: const [AppLocalizations.delegate], home: Builder( - builder: (context) { - return Text(AppLocalizations.of(context)!.appTitle); - }, + builder: (context) => Text(AppLocalizations.of(context)!.appTitle), ), );