Skip to content

Commit

Permalink
Refactor expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtanko committed Jul 18, 2024
1 parent 56ec9fe commit 5c9869a
Show file tree
Hide file tree
Showing 21 changed files with 384 additions and 429 deletions.
111 changes: 54 additions & 57 deletions lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,73 +13,70 @@ class MyApp extends StatelessWidget {
});

@override
Widget build(BuildContext context) {
return MultiRepositoryProvider(
providers: [
RepositoryProvider<EmailListRepository>(
create: (context) => EmailListRepository(),
),
RepositoryProvider<NavigationService>(
create: (context) => NavigationService(),
),
],
child: MultiBlocProvider(
Widget build(BuildContext context) => MultiRepositoryProvider(
providers: [
BlocProvider(
create: (context) => ThemeCubit(diContainer.get())..loadTheme(),
RepositoryProvider<EmailListRepository>(
create: (context) => EmailListRepository(),
),
BlocProvider(
create: (context) => EmailListBloc(
messagesRepository:
RepositoryProvider.of<EmailListRepository>(context),
)..add(
EmailListFetched(),
),
),
BlocProvider<InitBloc>(
create: (_) => InitBloc()
..add(
StartAppEvent(),
),
RepositoryProvider<NavigationService>(
create: (context) => NavigationService(),
),
],
child: Builder(
builder: (context) {
final navigator = NavigationService.of(context);
child: MultiBlocProvider(
providers: [
BlocProvider(
create: (context) => ThemeCubit(diContainer.get())..loadTheme(),
),
BlocProvider(
create: (context) => EmailListBloc(
messagesRepository:
RepositoryProvider.of<EmailListRepository>(context),
)..add(
EmailListFetched(),
),
),
BlocProvider<InitBloc>(
create: (_) => InitBloc()
..add(
StartAppEvent(),
),
),
],
child: Builder(
builder: (context) {
final navigator = NavigationService.of(context);

return MaterialApp(
debugShowCheckedModeBanner: kDebugMode,
restorationScopeId: 'app',
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en', ''), // English, no country code
Locale('de', ''), // Ukraine, no country code
],
onGenerateTitle: (BuildContext context) => S.of(context).appTitle,
theme: context.watch<ThemeCubit>().getDefaultTheme(),
darkTheme: context.watch<ThemeCubit>().darkTheme,
themeMode: context.watch<ThemeCubit>().themeMode,
navigatorKey: appNavigatorKey,
onGenerateRoute: navigator.onGenerateRoute,
builder: (_, child) {
return BlocListener<InitBloc, InitState>(
return MaterialApp(
debugShowCheckedModeBanner: kDebugMode,
restorationScopeId: 'app',
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en', ''), // English, no country code
Locale('de', ''), // Ukraine, no country code
],
onGenerateTitle: (BuildContext context) =>
S.of(context).appTitle,
theme: context.watch<ThemeCubit>().getDefaultTheme(),
darkTheme: context.watch<ThemeCubit>().darkTheme,
themeMode: context.watch<ThemeCubit>().themeMode,
navigatorKey: appNavigatorKey,
onGenerateRoute: navigator.onGenerateRoute,
builder: (_, child) => BlocListener<InitBloc, InitState>(
listener: (_, state) {
if (state is OpenApp) {
navigator.pushAndRemoveAll(Routes.app);
}
},
child: child,
);
},
);
},
),
);
},
),
),
),
);
}
);
}
5 changes: 2 additions & 3 deletions lib/di/di_repository_module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:injectable/injectable.dart';
@module
abstract class RepositoryModule {
@factoryMethod
ThemeRepository provideAccidentsRepository(ThemeStorage themeStorage) {
return ThemeRepositoryImpl(themeStorage);
}
ThemeRepository provideAccidentsRepository(ThemeStorage themeStorage) =>
ThemeRepositoryImpl(themeStorage);
}
4 changes: 1 addition & 3 deletions lib/features/contacts/contacts_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ class ContactsScreen extends StatelessWidget {
const ContactsScreen({super.key});

@override
Widget build(BuildContext context) {
return const Placeholder();
}
Widget build(BuildContext context) => const Placeholder();
}
28 changes: 13 additions & 15 deletions lib/features/email_list/email_list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,18 @@ class EmailListScreen extends StatelessWidget {
static const routeName = '/';

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(S.of(context).messagesTitle),
),
body: RefreshIndicator(
onRefresh: () async {
await Future<void>.delayed(const Duration(seconds: 1));
},
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: EmailListView(),
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: Text(S.of(context).messagesTitle),
),
),
);
}
body: RefreshIndicator(
onRefresh: () async {
await Future<void>.delayed(const Duration(seconds: 1));
},
child: SizedBox(
height: MediaQuery.of(context).size.height,
child: EmailListView(),
),
),
);
}
8 changes: 3 additions & 5 deletions lib/features/email_list/view/attachment_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ class AttachmentIcon extends StatelessWidget {
final VoidCallback? onTap;

@override
Widget build(BuildContext context) {
return attachment.type == AttachmentType.doc
? AppIcons.attachmentDoc
: AppIcons.attachmentPdf;
}
Widget build(BuildContext context) => attachment.type == AttachmentType.doc
? AppIcons.attachmentDoc
: AppIcons.attachmentPdf;
}
Loading

0 comments on commit 5c9869a

Please sign in to comment.