Skip to content

Commit

Permalink
fix: mobile debug and full height player not full height on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Dec 1, 2024
1 parent 09994f8 commit acb910a
Show file tree
Hide file tree
Showing 24 changed files with 323 additions and 306 deletions.
19 changes: 18 additions & 1 deletion lib/app/app_model.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:github/github.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:safe_change_notifier/safe_change_notifier.dart';
import 'package:yaru/theme.dart';

import '../constants.dart';
import '../expose/expose_service.dart';
Expand Down Expand Up @@ -61,9 +63,24 @@ class AppModel extends SafeChangeNotifier {

bool? _fullWindowMode;
bool? get fullWindowMode => _fullWindowMode;
void setFullWindowMode(bool? value) {
Future<void> setFullWindowMode(bool? value) async {
if (value == null || value == _fullWindowMode) return;
_fullWindowMode = value;

if (isMobile) {
if (_fullWindowMode == true) {
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
} else {
await SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: SystemUiOverlay.values,
);
await SystemChrome.setPreferredOrientations(
[],
);
}
}

notifyListeners();
}

Expand Down
180 changes: 5 additions & 175 deletions lib/app/view/app.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,18 @@
import 'dart:ui';

import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:phoenix_theme/phoenix_theme.dart' hide ColorX;
import 'package:system_theme/system_theme.dart';
import 'package:watch_it/watch_it.dart';
import 'package:yaru/yaru.dart';

import '../../common/view/theme.dart';
import '../../constants.dart';
import '../../external_path/external_path_service.dart';
import '../../l10n/l10n.dart';
import '../../library/library_model.dart';
import '../../radio/radio_model.dart';
import '../../settings/settings_model.dart';
import '../connectivity_model.dart';
import 'desktop_scaffold.dart';
import 'master_items.dart';
import 'splash_screen.dart';
import 'desktop_musicpod_app.dart';
import 'mobile_musicpod_app.dart';

class YaruMusicPodApp extends StatelessWidget {
const YaruMusicPodApp({super.key});

@override
Widget build(BuildContext context) {
return YaruTheme(
builder: (context, yaru, child) => _DesktopMusicPodApp(
builder: (context, yaru, child) => DesktopMusicPodApp(
highContrastTheme: yaruHighContrastLight,
highContrastDarkTheme: yaruHighContrastDark,
lightTheme: yaruLightWithTweaks(yaru),
Expand All @@ -42,165 +29,8 @@ class MaterialMusicPodApp extends StatelessWidget {
Widget build(BuildContext context) => SystemThemeBuilder(
builder: (context, accent) {
return isMobile
? _MobileMusicPodApp(accent: accent.accent)
: _DesktopMusicPodApp(accent: accent.accent);
? MobileMusicPodApp(accent: accent.accent)
: DesktopMusicPodApp(accent: accent.accent);
},
);
}

class _DesktopMusicPodApp extends StatefulWidget
with WatchItStatefulWidgetMixin {
const _DesktopMusicPodApp({
this.lightTheme,
this.darkTheme,
this.accent,
this.highContrastTheme,
this.highContrastDarkTheme,
});

final ThemeData? lightTheme,
darkTheme,
highContrastTheme,
highContrastDarkTheme;
final Color? accent;

@override
State<_DesktopMusicPodApp> createState() => _DesktopMusicPodAppState();
}

class _DesktopMusicPodAppState extends State<_DesktopMusicPodApp> {
late Future<bool> _initFuture;

@override
void initState() {
super.initState();
_initFuture = _init();
}

Future<bool> _init() async {
await di<ConnectivityModel>().init();
await di<LibraryModel>().init();
await di<RadioModel>().init();
if (!mounted) return false;
di<ExternalPathService>().init();
return true;
}

@override
Widget build(BuildContext context) {
final themeIndex = watchPropertyValue((SettingsModel m) => m.themeIndex);
final phoenix = phoenixTheme(color: widget.accent ?? Colors.greenAccent);
return MaterialApp(
debugShowCheckedModeBanner: false,
themeMode: ThemeMode.values[themeIndex],
highContrastTheme: widget.highContrastTheme,
highContrastDarkTheme: widget.highContrastDarkTheme,
theme: widget.lightTheme ?? phoenix.lightTheme,
darkTheme: widget.darkTheme ?? phoenix.darkTheme,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: supportedLocales,
onGenerateTitle: (context) => kAppTitle,
home: FutureBuilder(
future: _initFuture,
builder: (context, snapshot) {
return snapshot.data == true
? const DesktopScaffold()
: const SplashScreen();
},
),
scrollBehavior: const MaterialScrollBehavior().copyWith(
dragDevices: {
PointerDeviceKind.mouse,
PointerDeviceKind.touch,
PointerDeviceKind.stylus,
PointerDeviceKind.unknown,
PointerDeviceKind.trackpad,
},
),
);
}
}

class _MobileMusicPodApp extends StatefulWidget
with WatchItStatefulWidgetMixin {
const _MobileMusicPodApp({this.accent});

final Color? accent;

@override
State<_MobileMusicPodApp> createState() => _MobileMusicPodAppState();
}

class _MobileMusicPodAppState extends State<_MobileMusicPodApp> {
late Future<bool> _initFuture;

@override
void initState() {
super.initState();
_initFuture = _init();
}

Future<bool> _init() async {
await di<ConnectivityModel>().init();
await di<LibraryModel>().init();
await di<RadioModel>().init();
if (!mounted) return false;
di<ExternalPathService>().init();
return true;
}

@override
Widget build(BuildContext context) {
final themeIndex = watchPropertyValue((SettingsModel m) => m.themeIndex);
final phoenix = phoenixTheme(color: widget.accent ?? Colors.greenAccent);

final libraryModel = watchIt<LibraryModel>();
final masterItems = createMasterItems(libraryModel: libraryModel);

return MaterialApp(
navigatorKey: libraryModel.masterNavigatorKey,
navigatorObservers: [libraryModel],
initialRoute:
isMobile ? (libraryModel.selectedPageId ?? kLocalAudioPageId) : null,
onGenerateRoute: (settings) {
final page = (masterItems.firstWhereOrNull(
(e) => e.pageId == settings.name,
) ??
masterItems.elementAt(0))
.pageBuilder(context);

return PageRouteBuilder(
settings: settings,
pageBuilder: (_, __, ___) => FutureBuilder(
future: _initFuture,
builder: (context, snapshot) {
return snapshot.data == true ? page : const SplashScreen();
},
),
transitionsBuilder: (_, a, __, c) =>
FadeTransition(opacity: a, child: c),
);
},
debugShowCheckedModeBanner: false,
themeMode: ThemeMode.values[themeIndex],
theme: phoenix.lightTheme.copyWith(
navigationBarTheme: navigationBarTheme(theme: phoenix.lightTheme),
),
darkTheme: phoenix.darkTheme.copyWith(
navigationBarTheme: navigationBarTheme(theme: phoenix.darkTheme),
),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: supportedLocales,
onGenerateTitle: (context) => kAppTitle,
scrollBehavior: const MaterialScrollBehavior().copyWith(
dragDevices: {
PointerDeviceKind.mouse,
PointerDeviceKind.touch,
PointerDeviceKind.stylus,
PointerDeviceKind.unknown,
PointerDeviceKind.trackpad,
},
),
);
}
}
89 changes: 89 additions & 0 deletions lib/app/view/desktop_musicpod_app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:phoenix_theme/phoenix_theme.dart';
import 'package:watch_it/watch_it.dart';

import '../../constants.dart';
import '../../external_path/external_path_service.dart';
import '../../l10n/l10n.dart';
import '../../library/library_model.dart';
import '../../radio/radio_model.dart';
import '../../settings/settings_model.dart';
import '../connectivity_model.dart';
import 'desktop_scaffold.dart';
import 'splash_screen.dart';

class DesktopMusicPodApp extends StatefulWidget
with WatchItStatefulWidgetMixin {
const DesktopMusicPodApp({
super.key,
this.lightTheme,
this.darkTheme,
this.accent,
this.highContrastTheme,
this.highContrastDarkTheme,
});

final ThemeData? lightTheme,
darkTheme,
highContrastTheme,
highContrastDarkTheme;
final Color? accent;

@override
State<DesktopMusicPodApp> createState() => _DesktopMusicPodAppState();
}

class _DesktopMusicPodAppState extends State<DesktopMusicPodApp> {
late Future<bool> _initFuture;

@override
void initState() {
super.initState();
_initFuture = _init();
}

Future<bool> _init() async {
await di<ConnectivityModel>().init();
await di<LibraryModel>().init();
await di<RadioModel>().init();
if (!mounted) return false;
di<ExternalPathService>().init();
return true;
}

@override
Widget build(BuildContext context) {
final themeIndex = watchPropertyValue((SettingsModel m) => m.themeIndex);
final phoenix = phoenixTheme(color: widget.accent ?? Colors.greenAccent);
return MaterialApp(
debugShowCheckedModeBanner: false,
themeMode: ThemeMode.values[themeIndex],
highContrastTheme: widget.highContrastTheme,
highContrastDarkTheme: widget.highContrastDarkTheme,
theme: widget.lightTheme ?? phoenix.lightTheme,
darkTheme: widget.darkTheme ?? phoenix.darkTheme,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: supportedLocales,
onGenerateTitle: (context) => kAppTitle,
home: FutureBuilder(
future: _initFuture,
builder: (context, snapshot) {
return snapshot.data == true
? const DesktopScaffold()
: const SplashScreen();
},
),
scrollBehavior: const MaterialScrollBehavior().copyWith(
dragDevices: {
PointerDeviceKind.mouse,
PointerDeviceKind.touch,
PointerDeviceKind.stylus,
PointerDeviceKind.unknown,
PointerDeviceKind.trackpad,
},
),
);
}
}
Loading

0 comments on commit acb910a

Please sign in to comment.