Skip to content

Commit

Permalink
Move showWindowControls to HeaderBar (#647)
Browse files Browse the repository at this point in the history
* Move showWindowControls to HeaderBar
Fixes #646

* better default size
  • Loading branch information
Feichtmeier committed Apr 12, 2024
1 parent 5f36252 commit 1221f38
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 105 deletions.
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Future<void> main(List<String> args) async {
if (!Platform.isLinux) {
await windowManager.ensureInitialized();
WindowManager.instance.setMinimumSize(const Size(500, 700));
WindowManager.instance.setSize(const Size(950, 820));
}
}
WidgetsFlutterBinding.ensureInitialized();
Expand Down
1 change: 1 addition & 0 deletions lib/src/app/master_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MasterDetailPage extends ConsumerWidget {
appBar: HeaderBar(
backgroundColor: getSideBarColor(context.t),
style: YaruTitleBarStyle.undecorated,
adaptive: false,
title: const Text('MusicPod'),
actions: [
Padding(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/app/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _SplashScreenState extends State<SplashScreen>
Widget build(BuildContext context) {
final theme = context.t;
return Scaffold(
appBar: const HeaderBar(),
appBar: const HeaderBar(adaptive: false),
backgroundColor: theme.scaffoldBackgroundColor,
body: Center(
child: AnimatedOpacity(
Expand Down
31 changes: 10 additions & 21 deletions lib/src/common/audio_page.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yaru/yaru.dart';

import '../../app.dart';
import '../../common.dart';
import '../../data.dart';

Expand Down Expand Up @@ -98,25 +96,16 @@ class AudioPage extends StatelessWidget {
onAudioFilterSelected: onAudioFilterSelected,
);

return Consumer(
builder: (context, ref, _) {
final showWindowControls =
ref.watch(appModelProvider.select((a) => a.showWindowControls));

return YaruDetailPage(
key: ValueKey(pageId),
appBar: HeaderBar(
style: showWindowControls
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated,
title: isMobile ? null : (title ?? Text(headerTitle ?? pageId)),
leading: Navigator.canPop(context)
? const NavBackButton()
: const SizedBox.shrink(),
),
body: AdaptiveContainer(child: body),
);
},
return YaruDetailPage(
key: ValueKey(pageId),
appBar: HeaderBar(
adaptive: true,
title: isMobile ? null : (title ?? Text(headerTitle ?? pageId)),
leading: Navigator.canPop(context)
? const NavBackButton()
: const SizedBox.shrink(),
),
body: AdaptiveContainer(child: body),
);
}
}
Expand Down
54 changes: 35 additions & 19 deletions lib/src/common/common_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class HeaderBar extends StatelessWidget implements PreferredSizeWidget {
this.titleSpacing,
this.backgroundColor = Colors.transparent,
this.foregroundColor,
required this.adaptive,
});

final Widget? title;
Expand All @@ -142,28 +143,43 @@ class HeaderBar extends StatelessWidget implements PreferredSizeWidget {
final double? titleSpacing;
final Color? foregroundColor;
final Color? backgroundColor;
final bool adaptive;

@override
Widget build(BuildContext context) {
return !isMobile
? YaruWindowTitleBar(
titleSpacing: titleSpacing,
actions: actions,
leading: leading,
title: title,
border: BorderSide.none,
backgroundColor: backgroundColor,
style: style,
foregroundColor: foregroundColor,
)
: AppBar(
titleSpacing: titleSpacing,
centerTitle: true,
leading: leading,
title: title,
actions: actions,
foregroundColor: foregroundColor,
);
if (isMobile) {
return AppBar(
titleSpacing: titleSpacing,
centerTitle: true,
leading: leading,
title: title,
actions: actions,
foregroundColor: foregroundColor,
);
}

return Consumer(
builder: (context, ref, child) {
var theStyle = style;
if (adaptive) {
theStyle =
ref.watch(appModelProvider.select((a) => a.showWindowControls))
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated;
}

return YaruWindowTitleBar(
titleSpacing: titleSpacing,
actions: actions,
leading: leading,
title: title,
border: BorderSide.none,
backgroundColor: backgroundColor,
style: theStyle,
foregroundColor: foregroundColor,
);
},
);
}

@override
Expand Down
18 changes: 6 additions & 12 deletions lib/src/common/offline_page.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../app.dart';
import '../../build_context_x.dart';
import '../../globals.dart';
import 'common_widgets.dart';
import 'package:yaru/yaru.dart';

import '../../build_context_x.dart';
import '../../globals.dart';
import '../l10n/l10n.dart';
import 'common_widgets.dart';

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

@override
Widget build(BuildContext context, WidgetRef ref) {
final showWindowControls =
ref.watch(appModelProvider.select((v) => v.showWindowControls));
Widget build(BuildContext context) {
final theme = context.t;
return YaruDetailPage(
appBar: HeaderBar(
style: showWindowControls
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated,
adaptive: true,
title: Text(context.l10n.offline),
backgroundColor: Colors.transparent,
leading: navigatorKey.currentState?.canPop() == true
Expand Down
8 changes: 1 addition & 7 deletions lib/src/local_audio/artist_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yaru/yaru.dart';

import '../../app.dart';
import '../../common.dart';
import '../../constants.dart';
import '../../data.dart';
Expand Down Expand Up @@ -145,18 +144,13 @@ class _ArtistAlbumsCardGrid extends StatelessWidget {
Widget build(BuildContext context) {
return Consumer(
builder: (context, ref, _) {
final showWindowControls =
ref.watch(appModelProvider.select((a) => a.showWindowControls));

final artist = artistAudios?.firstOrNull?.artist;
final model = ref.read(localAudioModelProvider);
final playerModel = ref.read(playerModelProvider);

return YaruDetailPage(
appBar: HeaderBar(
style: showWindowControls
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated,
adaptive: true,
title: isMobile ? null : Text(artist ?? ''),
leading: Navigator.canPop(context)
? const NavBackButton()
Expand Down
7 changes: 1 addition & 6 deletions lib/src/local_audio/genre_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yaru/yaru.dart';

import '../../app.dart';
import '../../common.dart';
import '../../data.dart';
import '../../globals.dart';
Expand All @@ -17,18 +16,14 @@ class GenrePage extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final showWindowControls =
ref.watch(appModelProvider.select((a) => a.showWindowControls));
final model = ref.read(localAudioModelProvider);
final radioModel = ref.read(radioModelProvider);

final artistAudiosWithGenre = model.findArtistsOfGenre(Audio(genre: genre));

return YaruDetailPage(
appBar: HeaderBar(
style: showWindowControls
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated,
adaptive: true,
leading: (navigatorKey.currentState?.canPop() == true)
? const NavBackButton()
: const SizedBox.shrink(),
Expand Down
6 changes: 1 addition & 5 deletions lib/src/local_audio/local_audio_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class _LocalAudioPageState extends ConsumerState<LocalAudioPage> {

@override
Widget build(BuildContext context) {
final showWindowControls =
ref.watch(appModelProvider.select((a) => a.showWindowControls));
final appModel = ref.read(appModelProvider);

final model = ref.read(localAudioModelProvider);
Expand Down Expand Up @@ -87,9 +85,7 @@ class _LocalAudioPageState extends ConsumerState<LocalAudioPage> {
final localAudioView = LocalAudioView.values[index];

final headerBar = HeaderBar(
style: showWindowControls
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated,
adaptive: true,
leading: (navigatorKey.currentState?.canPop() == true)
? NavBackButton(
onPressed: () => search(text: null),
Expand Down
7 changes: 1 addition & 6 deletions lib/src/local_audio/local_audio_search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class LocalAudioSearchPage extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final showWindowControls =
ref.watch(appModelProvider.select((a) => a.showWindowControls));

final model = ref.read(localAudioModelProvider);
final appModel = ref.read(appModelProvider);
final titlesResult =
Expand Down Expand Up @@ -102,9 +99,7 @@ class LocalAudioSearchPage extends ConsumerWidget {

return YaruDetailPage(
appBar: HeaderBar(
style: showWindowControls
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated,
adaptive: true,
leading: (Navigator.of(context).canPop())
? const NavBackButton()
: const SizedBox.shrink(),
Expand Down
1 change: 1 addition & 0 deletions lib/src/player/full_height_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class FullHeightPlayer extends ConsumerWidget {
children: [
if (!isMobile)
HeaderBar(
adaptive: false,
title: const Text(
'',
maxLines: 1,
Expand Down
7 changes: 1 addition & 6 deletions lib/src/podcasts/podcasts_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ class _PodcastsPageState extends ConsumerState<PodcastsPage> {
final usePodcastIndex =
ref.watch(settingsModelProvider.select((m) => m.usePodcastIndex));

final showWindowControls =
ref.watch(appModelProvider.select((m) => m.showWindowControls));

final controlPanel = PodcastsControlPanel(
limit: limit,
setLimit: setLimit,
Expand Down Expand Up @@ -155,9 +152,7 @@ class _PodcastsPageState extends ConsumerState<PodcastsPage> {
)
: const SizedBox.shrink(),
titleSpacing: 0,
style: showWindowControls
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated,
adaptive: true,
actions: [
Flexible(
child: Padding(
Expand Down
7 changes: 1 addition & 6 deletions lib/src/radio/radio_discover_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:podcast_search/podcast_search.dart';
import 'package:yaru/yaru.dart';

import '../../app.dart';
import '../../common.dart';
import '../../constants.dart';
import '../../globals.dart';
Expand All @@ -19,8 +18,6 @@ class RadioDiscoverPage extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final showWindowControls =
ref.watch(appModelProvider.select((m) => m.showWindowControls));
final model = ref.read(radioModelProvider);
final libraryModel = ref.read(libraryModelProvider);
final searchQuery =
Expand Down Expand Up @@ -99,9 +96,7 @@ class RadioDiscoverPage extends ConsumerWidget {

return YaruDetailPage(
appBar: HeaderBar(
style: showWindowControls
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated,
adaptive: true,
leading: const NavBackButton(),
title: SizedBox(
width: kSearchBarWidth,
Expand Down
6 changes: 1 addition & 5 deletions lib/src/radio/radio_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ class _RadioPageState extends ConsumerState<RadioPage> {

@override
Widget build(BuildContext context) {
final showWindowControls =
ref.watch(appModelProvider.select((m) => m.showWindowControls));
final isOnline = ref.watch(appModelProvider.select((m) => m.isOnline));
if (!isOnline) return const OfflinePage();

Expand All @@ -87,9 +85,7 @@ class _RadioPageState extends ConsumerState<RadioPage> {

return YaruDetailPage(
appBar: HeaderBar(
style: showWindowControls
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated,
adaptive: true,
titleSpacing: 0,
leading: navigatorKey.currentState?.canPop() == true
? const NavBackButton()
Expand Down
7 changes: 1 addition & 6 deletions lib/src/radio/radio_search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yaru/yaru.dart';

import '../../app.dart';
import '../../common.dart';
import '../../data.dart';
import '../../globals.dart';
Expand Down Expand Up @@ -49,8 +48,6 @@ class _RadioSearchPageState extends ConsumerState<RadioSearchPage> {
Widget build(BuildContext context) {
final libraryModel = ref.read(libraryModelProvider);
final playerModel = ref.read(playerModelProvider);
final showWindowControls =
ref.watch(appModelProvider.select((a) => a.showWindowControls));

final futureBuilder = FutureBuilder(
future: _future,
Expand Down Expand Up @@ -100,9 +97,7 @@ class _RadioSearchPageState extends ConsumerState<RadioSearchPage> {

return YaruDetailPage(
appBar: HeaderBar(
style: showWindowControls
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated,
adaptive: true,
title: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand Down
6 changes: 1 addition & 5 deletions lib/src/radio/station_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ class StationPage extends ConsumerWidget {
];
const size = fullHeightPlayerImageSize - 20;

final showWindowControls =
ref.watch(appModelProvider.select((m) => m.showWindowControls));
final playerModel = ref.read(playerModelProvider);

ref.watch(libraryModelProvider.select((m) => m.starredStations.length));
Expand Down Expand Up @@ -173,9 +171,7 @@ class StationPage extends ConsumerWidget {

return YaruDetailPage(
appBar: HeaderBar(
style: showWindowControls
? YaruTitleBarStyle.normal
: YaruTitleBarStyle.undecorated,
adaptive: true,
title: Text(station.title ?? station.url ?? ''),
leading: Navigator.canPop(context)
? const NavBackButton()
Expand Down

0 comments on commit 1221f38

Please sign in to comment.