Skip to content

Commit

Permalink
Prefer Material over Platform Widgets for root widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedLSayed9 committed Jul 28, 2023
1 parent 74cba9c commit 9493b39
Show file tree
Hide file tree
Showing 66 changed files with 717 additions and 745 deletions.
2 changes: 1 addition & 1 deletion .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ migration:
- platform: root
create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
- platform: macos
- platform: web
create_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8
base_revision: f468f3366c26a5092eb964a230ce7892fda8f2f8

Expand Down
39 changes: 18 additions & 21 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'core/presentation/routing/app_router.dart';
import 'core/presentation/routing/navigation_service.dart';
import 'core/presentation/utils/riverpod_framework.dart';
import 'core/presentation/utils/scroll_behaviors.dart';
import 'core/presentation/widgets/platform_widgets/platform_app.dart';

class MyApp extends HookConsumerWidget {
const MyApp({super.key});
Expand All @@ -23,26 +22,24 @@ class MyApp extends HookConsumerWidget {
final theme = ref.watch(currentAppThemeProvider);
final locale = ref.watch(currentAppLocaleProvider);

return Theme(
data: theme.getThemeData(),
child: PlatformApp(
routerConfig: router,
builder: (_, child) {
return ScrollConfiguration(
behavior: MainScrollBehavior(),
child: GestureDetector(
onTap: NavigationService.removeFocus,
child: child,
),
);
},
title: 'Deliverzler',
color: Theme.of(context).colorScheme.primary,
locale: Locale(locale.code),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
debugShowCheckedModeBanner: false,
),
return MaterialApp.router(
routerConfig: router,
builder: (_, child) {
return ScrollConfiguration(
behavior: MainScrollBehavior(),
child: GestureDetector(
onTap: NavigationService.removeFocus,
child: child,
),
);
},
title: 'Deliverzler',
debugShowCheckedModeBanner: false,
color: Theme.of(context).colorScheme.primary,
theme: theme.getThemeData(locale.fontFamily),
locale: Locale(locale.code),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
);
}
}
41 changes: 37 additions & 4 deletions lib/auth/presentation/components/login_form_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import '../../../core/presentation/utils/event.dart';
import '../../../core/presentation/utils/fp_framework.dart';
import '../../../core/presentation/utils/riverpod_framework.dart';
import '../../../core/presentation/widgets/custom_button.dart';
import '../../../core/presentation/widgets/platform_widgets/platform_icons.dart';
import '../../domain/sign_in_with_email.dart';
import '../providers/sign_in_provider.dart';
import 'login_text_fields_section.dart';

class LoginFormComponent extends HookConsumerWidget {
const LoginFormComponent({super.key});
Expand All @@ -33,9 +33,42 @@ class LoginFormComponent extends HookConsumerWidget {
key: loginFormKey,
child: Column(
children: [
LoginTextFieldsSection(
emailController: emailController,
passwordController: passwordController,
TextFormField(
key: const ValueKey('login_email'),
controller: emailController,
decoration: InputDecoration(
hintText: tr(context).email,
suffixIcon: Padding(
padding: EdgeInsetsDirectional.only(
end: Theme.of(context).inputDecorationTheme.contentPadding!.horizontal / 2,
),
child: Icon(PlatformIcons.mail),
),
suffixIconConstraints: const BoxConstraints(),
),
validator: SignInWithEmail.validateEmail(context),
textInputAction: TextInputAction.next,
keyboardType: TextInputType.emailAddress,
),
const SizedBox(
height: Sizes.textFieldMarginV24,
),
TextFormField(
key: const ValueKey('login_password'),
controller: passwordController,
decoration: InputDecoration(
hintText: tr(context).password,
suffixIcon: Padding(
padding: EdgeInsetsDirectional.only(
end: Theme.of(context).inputDecorationTheme.contentPadding!.horizontal / 2,
),
child: Icon(PlatformIcons.password),
),
suffixIconConstraints: const BoxConstraints(),
),
validator: SignInWithEmail.validatePassword(context),
textInputAction: TextInputAction.go,
obscureText: true,
onFieldSubmitted: ref.isLoading(signInStateProvider) ? null : (_) => signIn(),
),
const SizedBox(
Expand Down
70 changes: 0 additions & 70 deletions lib/auth/presentation/components/login_text_fields_section.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';

import '../../../../core/presentation/utils/riverpod_framework.dart';
import '../../../../core/presentation/widgets/responsive_widgets/widget_builders.dart';
import '../../../../core/presentation/widgets/responsive_widgets/responsive_layouts.dart';
import '../../providers/sign_in_provider.dart';
import 'sign_in_screen_compact.dart';
import 'sign_in_screen_medium.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';

import '../../../../core/presentation/screens/full_screen_platform_scaffold.dart';
import '../../../../core/presentation/screens/full_screen_scaffold.dart';
import '../../../../core/presentation/styles/sizes.dart';
import '../../../../gen/my_assets.dart';
import '../../components/login_content_component.dart';
Expand All @@ -11,7 +11,7 @@ class SignInScreenCompact extends StatelessWidget {

@override
Widget build(BuildContext context) {
return FullScreenPlatformScaffold(
return FullScreenScaffold(
body: CustomScrollView(
slivers: [
SliverFillRemaining(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';

import '../../../../core/presentation/screens/full_screen_platform_scaffold.dart';
import '../../../../core/presentation/screens/full_screen_scaffold.dart';
import '../../../../core/presentation/styles/sizes.dart';
import '../../../../gen/my_assets.dart';
import '../../components/login_content_component.dart';
Expand All @@ -11,7 +11,7 @@ class SignInScreenMedium extends StatelessWidget {

@override
Widget build(BuildContext context) {
return FullScreenPlatformScaffold(
return FullScreenScaffold(
body: CustomScrollView(
slivers: [
SliverFillRemaining(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import 'package:flutter/material.dart';

import '../../../../../gen/my_assets.dart';
import '../../../../presentation/helpers/localization_helper.dart';
import '../../../../presentation/styles/font_styles.dart';

enum AppLocale {
english('en', MyAssets.ASSETS_ICONS_LANGUAGES_ICONS_ENGLISH_PNG),
arabic('ar', MyAssets.ASSETS_ICONS_LANGUAGES_ICONS_ARABIC_PNG);
english('en', MyAssets.ASSETS_ICONS_LANGUAGES_ICONS_ENGLISH_PNG, FontStyles.familyPoppins),
arabic('ar', MyAssets.ASSETS_ICONS_LANGUAGES_ICONS_ARABIC_PNG, FontStyles.familyTajawal);

const AppLocale(this.code, this.flag);
const AppLocale(this.code, this.flag, this.fontFamily);

final String code;
final String flag;
final String fontFamily;
}

extension LanguageExtension on AppLocale {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ enum AppTheme {
}

extension ThemeExtension on AppTheme {
ThemeData getThemeData() {
ThemeData getThemeData(String fontFamily) {
return switch (this) {
AppTheme.light => ThemeLight().getThemeData(),
AppTheme.dark => ThemeDark().getThemeData(),
AppTheme.light => ThemeLight().getThemeData(fontFamily),
AppTheme.dark => ThemeDark().getThemeData(fontFamily),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ abstract class ITheme {

abstract final Color scaffoldBackgroundColor;

abstract final Color bottomAppBarColor;
abstract final NavigationBarThemeData navigationBarTheme;

abstract final NavigationRailThemeData navigationRailTheme;

abstract final TextTheme textTheme;

abstract final TextTheme primaryTextTheme;

abstract final Color hintColor;

abstract final TextSelectionThemeData textSelectionTheme;
Expand All @@ -38,23 +42,27 @@ abstract class ITheme {
}

extension ThemeExtension on ITheme {
ThemeData getThemeData() {
//TODO(AHMED): useMaterial3
ThemeData getThemeData(String fontFamily) {
return baseTheme.copyWith(
appBarTheme: appBarTheme,
scaffoldBackgroundColor: scaffoldBackgroundColor,
navigationBarTheme: navigationBarTheme,
navigationRailTheme: navigationRailTheme,
primaryColor: primaryColor,
colorScheme: colorScheme,
textTheme: textTheme.apply(fontFamily: fontFamily),
primaryTextTheme: primaryTextTheme.apply(fontFamily: fontFamily),
iconTheme: iconTheme,
buttonTheme: buttonTheme,
toggleButtonsTheme: toggleButtonsTheme,
textTheme: textTheme,
hintColor: hintColor,
textSelectionTheme: textSelectionTheme,
inputDecorationTheme: inputDecorationTheme,
cardTheme: cardTheme,
extensions: [
this.customColors,
], bottomAppBarTheme: BottomAppBarTheme(color: bottomAppBarColor),
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,37 @@ class ThemeDark implements ITheme {
late final Color scaffoldBackgroundColor = appColors.scaffoldBGColor;

@override
late final Color bottomAppBarColor = appColors.bottomNavBarColor;
late final NavigationBarThemeData navigationBarTheme = NavigationBarThemeData(
backgroundColor: appColors.bottomNavBarColor,
surfaceTintColor: Colors.transparent,
shadowColor: appColors.bottomNavBarColor,
indicatorColor: Colors.blue.shade100,
labelTextStyle: MaterialStateProperty.resolveWith((states) {
return TextStyle(
color: appColors.customColors.font14Color,
fontSize: Sizes.font12,
);
}),
elevation: 4,
);

@override
late final NavigationRailThemeData navigationRailTheme = NavigationRailThemeData(
backgroundColor: appColors.bottomNavBarColor,
elevation: 4,
);

@override
late final TextTheme textTheme = TextTheme(
titleMedium: TextStyle(
color: appColors.textFieldSubtitle1Color,
fontSize: Sizes.font14,
),
);

@override
late final TextTheme primaryTextTheme = baseTheme.primaryTextTheme;

@override
late final Color hintColor = appColors.textFieldHintColor;

Expand All @@ -58,7 +80,17 @@ class ThemeDark implements ITheme {

@override
late final InputDecorationTheme inputDecorationTheme = InputDecorationTheme(
contentPadding: const EdgeInsets.symmetric(
vertical: Sizes.textFieldPaddingV14,
horizontal: Sizes.textFieldPaddingH14,
),
isDense: true,
filled: true,
fillColor: appColors.textFieldFillColor,
hintStyle: TextStyle(
fontSize: Sizes.font12,
color: appColors.textFieldHintColor,
),
prefixIconColor: appColors.textFieldPrefixIconColor,
suffixIconColor: appColors.textFieldSuffixIconColor,
border: OutlineInputBorder(
Expand Down Expand Up @@ -97,8 +129,18 @@ class ThemeDark implements ITheme {
width: 0.8,
),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: const BorderRadius.all(
Radius.circular(Sizes.textFieldR12),
),
borderSide: BorderSide(
color: appColors.textFieldErrorBorderColor,
width: 0.8,
),
),
errorStyle: TextStyle(
color: appColors.textFieldErrorStyleColor,
fontSize: Sizes.font12,
),
);

Expand Down
Loading

0 comments on commit 9493b39

Please sign in to comment.