Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/lint-and-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
build:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4
- uses: monterail/flutter-action@v1
with:
Expand Down
8 changes: 2 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> boot() async {
Expand Down
10 changes: 4 additions & 6 deletions lib/src/modules/bloc_screen/bloc/counter_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ class CounterBloc extends Bloc<CounterEvent, CounterState> {
on<_Increased>(_onIncreased);
}

void _onIncreased(_Increased event, Emitter<CounterState> emit) {
emit(state.copyWith(value: state.value + 1));
}
void _onIncreased(_Increased event, Emitter<CounterState> emit) =>
emit(state.copyWith(value: state.value + 1));

void _onDecreased(_Decreased event, Emitter<CounterState> emit) {
emit(state.copyWith(value: state.value - 1));
}
void _onDecreased(_Decreased event, Emitter<CounterState> emit) =>
emit(state.copyWith(value: state.value - 1));
}
49 changes: 24 additions & 25 deletions lib/src/modules/bloc_screen/view/bloc_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,31 @@ class BlocScreen extends StatelessWidget {
body: BlocProvider(
create: (context) => CounterBloc(),
child: BlocBuilder<CounterBloc, CounterState>(
builder: (context, state) {
return Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
FloatingActionButton(
heroTag: 'minusBtn',
onPressed:
() => context.read<CounterBloc>().add(
const CounterEvent.decreased(),
),
child: const Icon(Icons.remove),
),
Text('${state.value}'),
FloatingActionButton(
heroTag: 'plusBtn',
onPressed:
() => context.read<CounterBloc>().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<CounterBloc>().add(
const CounterEvent.decreased(),
),
child: const Icon(Icons.remove),
),
Text('${state.value}'),
FloatingActionButton(
heroTag: 'plusBtn',
onPressed:
() => context.read<CounterBloc>().add(
const CounterEvent.increased(),
),
child: const Icon(Icons.add),
),
],
),
),
);
},
),
),
);
Expand Down
37 changes: 18 additions & 19 deletions lib/src/modules/cubit_screen/view/cubit_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,25 @@ class CubitScreen extends StatelessWidget {
body: BlocProvider(
create: (context) => CounterCubit(),
child: BlocBuilder<CounterCubit, CounterState>(
builder: (context, state) {
return Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
FloatingActionButton(
heroTag: 'minusBtn',
onPressed: () => context.read<CounterCubit>().decrement(),
child: const Icon(Icons.remove),
),
Text('${state.value}'),
FloatingActionButton(
heroTag: 'plusBtn',
onPressed: () => context.read<CounterCubit>().increment(),
child: const Icon(Icons.add),
),
],
builder:
(context, state) => Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
FloatingActionButton(
heroTag: 'minusBtn',
onPressed: () => context.read<CounterCubit>().decrement(),
child: const Icon(Icons.remove),
),
Text('${state.value}'),
FloatingActionButton(
heroTag: 'plusBtn',
onPressed: () => context.read<CounterCubit>().increment(),
child: const Icon(Icons.add),
),
],
),
),
);
},
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/modules/main_screen/bloc/main_screen_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MainScreenBloc extends Bloc<MainScreenEvent, MainScreenState> {
Emitter<MainScreenState> 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)),
Expand Down
157 changes: 80 additions & 77 deletions lib/src/modules/main_screen/view/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<MainScreenBloc, MainScreenState>(
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<MainScreenBloc>().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<MainScreenBloc>().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),
),
],
),
),
),
),
Expand All @@ -106,12 +107,14 @@ class MainScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () => context.read<MainScreenBloc>().add(RemoveUserEvent()),
onPressed:
() => context.read<MainScreenBloc>().add(const RemoveUserEvent()),
child: const Text('Remove'),
),
const SizedBox(width: 16),
ElevatedButton(
onPressed: () => context.read<MainScreenBloc>().add(AddUserEvent()),
onPressed:
() => context.read<MainScreenBloc>().add(const AddUserEvent()),
child: const Text('Add'),
),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/src/services/sembast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Future<void> 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);
}
}
Expand Down
6 changes: 6 additions & 0 deletions lints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ linter:
- avoid_void_async
- sort_constructors_first
- unawaited_futures
- unnecessary_await_in_return
- unnecessary_breaks
- unnecessary_parenthesis
- unnecessary_raw_strings
Expand All @@ -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
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/src/services/sembast_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 1 addition & 3 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
);

Expand Down