Skip to content

Commit

Permalink
Merge branch 'main' into managepage-cancel-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
codinesh authored Dec 28, 2023
2 parents a506031 + 513aefd commit 1278f30
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 51 deletions.
11 changes: 9 additions & 2 deletions packages/app_center/lib/src/explore/explore_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:app_center/l10n.dart';
import 'package:app_center/layout.dart';
import 'package:app_center/snapd.dart';
import 'package:app_center/src/store/store_pages.dart';
import 'package:app_center/store.dart';
import 'package:app_center/widgets.dart';
import 'package:collection/collection.dart';
Expand Down Expand Up @@ -172,8 +173,14 @@ class _CategoryBanner extends ConsumerWidget {
snaps: featuredSnaps?.take(kNumberOfBannerSnaps).toList() ?? [],
slogan: category.slogan(l10n),
buttonLabel: category.buttonLabel(l10n),
onPressed: () =>
StoreNavigator.pushSearch(context, category: category.categoryName),
onPressed: () {
if (displayedCategories.contains(category)) {
ref.read(yaruPageControllerProvider).index =
displayedCategories.indexOf(category) + 1;
} else {
StoreNavigator.pushSearch(context, category: category.categoryName);
}
},
colors: category.bannerColors,
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/app_center/lib/src/l10n/app_en.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"appCenterLabel": "App Center",
"appstreamSearchGreylist": "app;application;package;program;programme;suite;tool",
"snapPageChannelLabel": "Channel",
"snapPageConfinementLabel": "Confinement",
Expand Down
104 changes: 62 additions & 42 deletions packages/app_center/lib/src/store/store_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import 'package:yaru_widgets/yaru_widgets.dart';
final materialAppNavigatorKeyProvider =
Provider((ref) => GlobalKey<NavigatorState>());

final yaruPageControllerProvider =
Provider((ref) => YaruPageController(length: pages.length));

class StoreApp extends ConsumerStatefulWidget {
const StoreApp({super.key});

Expand All @@ -43,55 +46,72 @@ class _StoreAppState extends ConsumerState<StoreApp> {
localizationsDelegates: localizationsDelegates,
navigatorKey: ref.watch(materialAppNavigatorKeyProvider),
supportedLocales: supportedLocales,
home: Scaffold(
appBar: YaruWindowTitleBar(
title: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: kSearchBarWidth),
child: SearchField(
onSearch: (query) =>
_navigator.pushAndRemoveSearch(query: query),
onSnapSelected: (name) => _navigator.pushSnap(name: name),
onDebSelected: (id) => _navigator.pushDeb(id: id),
home: YaruWindowTitleSetter(
child: Scaffold(
appBar: YaruWindowTitleBar(
title: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: kSearchBarWidth),
child: SearchField(
onSearch: (query) =>
_navigator.pushAndRemoveSearch(query: query),
onSnapSelected: (name) => _navigator.pushSnap(name: name),
onDebSelected: (id) => _navigator.pushDeb(id: id),
),
),
),
),
body: YaruMasterDetailPage(
navigatorKey: _navigatorKey,
navigatorObservers: [StoreObserver(ref)],
initialRoute: ref.watch(initialRouteProvider),
length: pages.length,
tileBuilder: (context, index, selected, availableWidth) =>
pages[index].tileBuilder(context, selected),
pageBuilder: (context, index) => pages[index].pageBuilder(context),
layoutDelegate: const YaruMasterFixedPaneDelegate(
paneWidth: kPaneWidth,
),
breakpoint: 0, // always landscape
onGenerateRoute: (settings) =>
switch (StoreRoutes.routeOf(settings)) {
StoreRoutes.deb => MaterialPageRoute(
settings: settings,
builder: (_) => DebPage(
id: StoreRoutes.debOf(settings)!,
)),
StoreRoutes.snap => MaterialPageRoute(
settings: settings,
builder: (_) => SnapPage(
snapName: StoreRoutes.snapOf(settings)!,
body: YaruMasterDetailPage(
navigatorKey: _navigatorKey,
navigatorObservers: [StoreObserver(ref)],
initialRoute: ref.watch(initialRouteProvider),
controller: ref.watch(yaruPageControllerProvider),
tileBuilder: (context, index, selected, availableWidth) =>
pages[index].tileBuilder(context, selected),
pageBuilder: (context, index) =>
pages[index].pageBuilder(context),
layoutDelegate: const YaruMasterFixedPaneDelegate(
paneWidth: kPaneWidth,
),
breakpoint: 0, // always landscape
onGenerateRoute: (settings) =>
switch (StoreRoutes.routeOf(settings)) {
StoreRoutes.deb => MaterialPageRoute(
settings: settings,
builder: (_) => DebPage(
id: StoreRoutes.debOf(settings)!,
)),
StoreRoutes.snap => MaterialPageRoute(
settings: settings,
builder: (_) => SnapPage(
snapName: StoreRoutes.snapOf(settings)!,
),
),
),
StoreRoutes.search => MaterialPageRoute(
settings: settings,
builder: (_) => SearchPage(
query: StoreRoutes.queryOf(settings),
category: StoreRoutes.categoryOf(settings),
StoreRoutes.search => MaterialPageRoute(
settings: settings,
builder: (_) => SearchPage(
query: StoreRoutes.queryOf(settings),
category: StoreRoutes.categoryOf(settings),
),
),
),
_ => null,
},
_ => null,
},
),
),
),
),
);
}
}

class YaruWindowTitleSetter extends StatelessWidget {
const YaruWindowTitleSetter({required this.child, super.key});

final Widget child;

@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
YaruWindow.of(context).setTitle(l10n.appCenterLabel);

return child;
}
}
14 changes: 8 additions & 6 deletions packages/app_center/lib/src/store/store_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

final displayedCategories = [
SnapCategoryEnum.featured,
SnapCategoryEnum.productivity,
SnapCategoryEnum.development,
SnapCategoryEnum.games,
];

typedef StorePage = ({
Widget Function(BuildContext context, bool selected) tileBuilder,
WidgetBuilder pageBuilder,
Expand All @@ -21,12 +28,7 @@ final pages = <StorePage>[
),
pageBuilder: (_) => const ExplorePage(),
),
for (final category in [
SnapCategoryEnum.featured,
SnapCategoryEnum.productivity,
SnapCategoryEnum.development,
SnapCategoryEnum.games,
])
for (final category in displayedCategories)
(
tileBuilder: (context, selected) => YaruMasterTile(
leading: Icon(category.icon(true)),
Expand Down
3 changes: 2 additions & 1 deletion packages/app_center/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ dependencies:
yaru: ^1.2.0
yaru_icons: ^2.2.2
yaru_test: ^0.1.5
yaru_widgets: ^3.3.0
yaru_widgets: ^3.4.0
yaru_window: ^0.2.0

dev_dependencies:
build_runner: ^2.4.6
Expand Down

0 comments on commit 1278f30

Please sign in to comment.