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

Commit

Permalink
fix: Fix widget positions
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Oct 12, 2023
1 parent 10503af commit 39191c5
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 185 deletions.
271 changes: 150 additions & 121 deletions lib/App.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ import 'package:locus/widgets/DismissKeyboard.dart';
import 'package:modal_bottom_sheet/modal_bottom_sheet.dart';
import 'package:provider/provider.dart';

import 'app_wrappers/CheckViewAlarmsLive.dart';
import 'app_wrappers/HandleNotifications.dart';
import 'app_wrappers/InitCurrentLocationFromSettings.dart';
import 'app_wrappers/ManageQuickActions.dart';
import 'app_wrappers/PublishTaskPositionsOnUpdate.dart';
import 'app_wrappers/RegisterBackgroundListeners.dart';
import 'app_wrappers/ShowUpdateDialog.dart';
import 'app_wrappers/UniLinksHandler.dart';
import 'app_wrappers/UpdateLastLocationToSettings.dart';
import 'app_wrappers/UpdateLocaleToSettings.dart';
import 'app_wrappers/UpdateLocationHistory.dart';
import 'constants/themes.dart';

ColorScheme createColorScheme(
Expand Down Expand Up @@ -51,83 +62,115 @@ class App extends StatelessWidget {
child: DynamicColorBuilder(
builder:
(ColorScheme? lightColorScheme, ColorScheme? darkColorScheme) =>
PlatformApp(
title: 'Locus',
material: (_, __) => MaterialAppData(
theme: (() {
if (lightColorScheme != null) {
Expanded(
child: PlatformApp(
title: 'Locus',
material: (_, __) => MaterialAppData(
theme: (() {
if (lightColorScheme != null) {
return LIGHT_THEME_MATERIAL.copyWith(
colorScheme: settings.primaryColor == null
? lightColorScheme
: createColorScheme(
lightColorScheme,
settings.primaryColor!,
Brightness.light,
),
primaryColor:
settings.primaryColor ?? lightColorScheme.primary,
);
}

return LIGHT_THEME_MATERIAL.copyWith(
colorScheme: settings.primaryColor == null
? lightColorScheme
? null
: createColorScheme(
lightColorScheme,
lightColorScheme ??
ColorScheme.fromSwatch(
primarySwatch:
createMaterialColor(settings.primaryColor!),
),
settings.primaryColor!,
Brightness.light,
),
primaryColor:
settings.primaryColor ?? lightColorScheme.primary,
primaryColor: settings.primaryColor,
);
}

return LIGHT_THEME_MATERIAL.copyWith(
colorScheme: settings.primaryColor == null
? null
: createColorScheme(
lightColorScheme ??
ColorScheme.fromSwatch(
primarySwatch:
createMaterialColor(settings.primaryColor!),
),
settings.primaryColor!,
Brightness.light,
),
primaryColor: settings.primaryColor,
);
})(),
darkTheme: (() {
if (settings.getAndroidTheme() == AndroidTheme.miui) {
return DARK_THEME_MATERIAL_MIUI.copyWith(
colorScheme: settings.primaryColor == null
? null
: createColorScheme(
const ColorScheme.dark(),
settings.primaryColor!,
Brightness.dark,
})(),
darkTheme: (() {
if (settings.getAndroidTheme() == AndroidTheme.miui) {
return DARK_THEME_MATERIAL_MIUI.copyWith(
colorScheme: settings.primaryColor == null
? null
: createColorScheme(
const ColorScheme.dark(),
settings.primaryColor!,
Brightness.dark,
),
primaryColor: settings.primaryColor,
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor:
settings.primaryColor ?? MIUI_PRIMARY_COLOR,
foregroundColor: Colors.white,
splashFactory: NoSplash.splashFactory,
textStyle: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w700,
),
primaryColor: settings.primaryColor,
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor:
settings.primaryColor ?? MIUI_PRIMARY_COLOR,
foregroundColor: Colors.white,
splashFactory: NoSplash.splashFactory,
textStyle: const TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w700,
),
),
),
);
}
);
}

if (darkColorScheme != null) {
return DARK_THEME_MATERIAL.copyWith(
colorScheme: settings.primaryColor == null
? darkColorScheme
: createColorScheme(
darkColorScheme,
settings.primaryColor!,
Brightness.dark,
),
primaryColor:
settings.primaryColor ?? darkColorScheme.primary,
scaffoldBackgroundColor: HSLColor.fromColor(
settings.primaryColor ?? darkColorScheme.background)
.withLightness(0.08)
.toColor(),
dialogBackgroundColor: settings.primaryColor == null
? darkColorScheme.background
: HSLColor.fromColor(settings.primaryColor!)
.withLightness(0.15)
.toColor(),
inputDecorationTheme:
DARK_THEME_MATERIAL.inputDecorationTheme.copyWith(
fillColor: settings.primaryColor == null
? null
: HSLColor.fromColor(settings.primaryColor!)
.withLightness(0.3)
.withSaturation(.5)
.toColor(),
),
);
}

if (darkColorScheme != null) {
return DARK_THEME_MATERIAL.copyWith(
colorScheme: settings.primaryColor == null
? darkColorScheme
? null
: createColorScheme(
darkColorScheme,
const ColorScheme.dark(),
settings.primaryColor!,
Brightness.dark,
),
primaryColor:
settings.primaryColor ?? darkColorScheme.primary,
scaffoldBackgroundColor: HSLColor.fromColor(
settings.primaryColor ?? darkColorScheme.background)
.withLightness(0.08)
.toColor(),
primaryColor: settings.primaryColor,
scaffoldBackgroundColor: settings.primaryColor == null
? null
: HSLColor.fromColor(settings.primaryColor!)
.withLightness(0.08)
.toColor(),
dialogBackgroundColor: settings.primaryColor == null
? darkColorScheme.background
? null
: HSLColor.fromColor(settings.primaryColor!)
.withLightness(0.15)
.toColor(),
Expand All @@ -141,74 +184,60 @@ class App extends StatelessWidget {
.toColor(),
),
);
}
})(),
themeMode: ThemeMode.system,
),
cupertino: (_, __) => CupertinoAppData(
theme: settings.primaryColor == null
? LIGHT_THEME_CUPERTINO
: LIGHT_THEME_CUPERTINO.copyWith(
primaryColor: settings.primaryColor,
),
),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
builder: (context, child) => Stack(
children: [
const UpdateLocationHistory(),
const UniLinksHandler(),
const UpdateLastLocationToSettings(),
const RegisterBackgroundListeners(),
const UpdateLocaleToSettings(),
const HandleNotifications(),
const CheckViewAlarmsLive(),
const ManageQuickActions(),
const InitCurrentLocationFromSettings(),
const ShowUpdateDialog(),
const PublishTaskPositionsOnUpdate(),
if (child != null) child,
],
),
onGenerateRoute: (routeSettings) {
final screen = (() {
if (settings.getRequireBiometricAuthenticationOnStart()) {
return const BiometricsRequiredStartupScreen();
}

return DARK_THEME_MATERIAL.copyWith(
colorScheme: settings.primaryColor == null
? null
: createColorScheme(
const ColorScheme.dark(),
settings.primaryColor!,
Brightness.dark,
),
primaryColor: settings.primaryColor,
scaffoldBackgroundColor: settings.primaryColor == null
? null
: HSLColor.fromColor(settings.primaryColor!)
.withLightness(0.08)
.toColor(),
dialogBackgroundColor: settings.primaryColor == null
? null
: HSLColor.fromColor(settings.primaryColor!)
.withLightness(0.15)
.toColor(),
inputDecorationTheme:
DARK_THEME_MATERIAL.inputDecorationTheme.copyWith(
fillColor: settings.primaryColor == null
? null
: HSLColor.fromColor(settings.primaryColor!)
.withLightness(0.3)
.withSaturation(.5)
.toColor(),
),
);
})(),
themeMode: ThemeMode.system,
),
cupertino: (_, __) => CupertinoAppData(
theme: settings.primaryColor == null
? LIGHT_THEME_CUPERTINO
: LIGHT_THEME_CUPERTINO.copyWith(
primaryColor: settings.primaryColor,
),
),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
onGenerateRoute: (routeSettings) {
final screen = (() {
if (settings.getRequireBiometricAuthenticationOnStart()) {
return const BiometricsRequiredStartupScreen();
}
if (!settings.userHasSeenWelcomeScreen) {
return const WelcomeScreen();
}

if (!settings.userHasSeenWelcomeScreen) {
return const WelcomeScreen();
}
return const LocationsOverviewScreen();
})();

return const LocationsOverviewScreen();
})();
if (isCupertino(context)) {
return MaterialWithModalsPageRoute(
builder: (_) => screen,
settings: routeSettings,
);
}

if (isCupertino(context)) {
return MaterialWithModalsPageRoute(
return NativePageRoute(
builder: (_) => screen,
settings: routeSettings,
context: context,
);
}

return NativePageRoute(
builder: (_) => screen,
context: context,
);
},
},
),
),
),
);
Expand Down
4 changes: 2 additions & 2 deletions lib/app_wrappers/CheckViewAlarmsLive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class CheckViewAlarmsLive extends StatefulWidget {
}

class _CheckViewAlarmsLiveState extends State<CheckViewAlarmsLive> {
late final CurrentLocationService _currentLocation;
late final StreamSubscription<Position> _subscription;

@override
void initState() {
super.initState();

_subscription = _currentLocation.stream.listen((position) async {
final currentLocation = context.read<CurrentLocationService>();
_subscription = currentLocation.stream.listen((position) async {
final l10n = AppLocalizations.of(context);
final viewService = context.read<ViewService>();
final userLocation = await LocationPointService.fromPosition(position);
Expand Down
13 changes: 8 additions & 5 deletions lib/app_wrappers/InitCurrentLocationFromSettings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ class _InitCurrentLocationFromSettingsState
super.initState();

_currentLocation = context.read<CurrentLocationService>();
final settings = context.read<SettingsService>();
final lastLocation = settings.getLastMapLocation();

if (lastLocation != null) {
_setLocation(lastLocation);
}
WidgetsBinding.instance.addPostFrameCallback((_) {
final settings = context.read<SettingsService>();
final lastLocation = settings.getLastMapLocation();

if (lastLocation != null) {
_setLocation(lastLocation);
}
});
}

void _setLocation(final SettingsLastMapLocation rawLocation) {
Expand Down
Loading

0 comments on commit 39191c5

Please sign in to comment.