Skip to content

Commit

Permalink
fix context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
laiiihz committed Nov 24, 2023
1 parent 12fd2f0 commit 70faac2
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lib/ui/alga_view/alga_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AlgaShellRouteView extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
if (ref.watch(isDesktop)) {
if (ref.watch(isDesktopProvider)) {
return Material(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
Expand Down
74 changes: 54 additions & 20 deletions lib/ui/alga_view/all_apps/alga_app_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,29 @@ class AlgaAppItem extends StatelessWidget {
valueListenable: FavoriteBox.listener(item.path),
builder: (context, _, child) {
final state = FavoriteBox.get(item);
return Material(
color: colorScheme.surfaceVariant,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: state
? BorderSide(color: colorScheme.primary, width: 2)
: BorderSide.none,
),
clipBehavior: Clip.hardEdge,
child: GestureDetector(
onTap: () {
GoRouter.of(context).go(item.path);
},
onLongPressStart: (detail) {
_showMenu(context, detail.localPosition, state);
},
onSecondaryTapUp: (detail) {
_showMenu(context, detail.localPosition, state);
},
child: child,
return GestureDetector(
onLongPressStart: (detail) {},
child: Material(
color: colorScheme.surfaceVariant,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: state
? BorderSide(color: colorScheme.primary, width: 2)
: BorderSide.none,
),
clipBehavior: Clip.hardEdge,
child: InkWell(
onTap: () {
GoRouter.of(context).go(item.path);
},
onSecondaryTapUp: (detail) {
_showMenu(context, detail.localPosition, state);
},
onLongPress: () {
_showMenuModal(context, state);
},
child: child,
),
),
);
},
Expand Down Expand Up @@ -128,4 +131,35 @@ class AlgaAppItem extends StatelessWidget {
default:
}
}

_showMenuModal(BuildContext context, bool like) async {
final colorScheme = Theme.of(context).colorScheme;

showModalBottomSheet(
context: context,
showDragHandle: true,
builder: (context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
title: like
? Text(
context.tr.removeFavorite,
style: TextStyle(color: colorScheme.error),
)
: Text(context.tr.addFavorite),
trailing: like
? Icon(Icons.delete_rounded, color: colorScheme.error)
: Icon(Icons.favorite_rounded, color: colorScheme.tertiary),
onTap: () {
FavoriteBox.update(item);
Navigator.of(context).pop();
},
),
],
);
},
);
}
}
23 changes: 19 additions & 4 deletions lib/ui/alga_view/all_apps/alga_app_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import 'dart:io';

import 'package:alga/models/app_atom.dart';
import 'package:alga/models/app_category.dart';
import 'package:alga/routers/app_router.dart';
import 'package:alga/ui/global.provider.dart';
import 'package:alga/ui/views/search_view.dart';
import 'package:alga/utils/constants/import_helper.dart';

import 'alga_app_item.dart';
Expand All @@ -12,22 +17,32 @@ class AppsRoute extends GoRouteData {
}
}

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

@override
State<AlgaAppView> createState() => AlgaAppViewState();
ConsumerState<AlgaAppView> createState() => AlgaAppViewState();
}

class AlgaAppViewState extends State<AlgaAppView>
class AlgaAppViewState extends ConsumerState<AlgaAppView>
with SingleTickerProviderStateMixin {
@override
Widget build(BuildContext context) {
final isDesktop = ref.watch(isDesktopProvider);
return Scaffold(
appBar: AppBar(
title: Text(S.of(context).appName),
centerTitle: false,
centerTitle: Platform.isIOS,
bottom: const AppCategoriesPanel(),
actions: [
if (!isDesktop)
IconButton(
onPressed: () {
SearchRoute().push(context);
},
icon: const Icon(Icons.search_rounded),
),
],
),
body: Consumer(builder: (context, ref, _) {
return TabBarView(
Expand Down
11 changes: 2 additions & 9 deletions lib/ui/alga_view/widgets/alga_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class _AlgaNavigationBarState extends State<AlgaNavigationBar> {
final location = GoRouterState.of(context).matchedLocation;
if (location.startsWith(AppsRoute().location)) return 0;
if (location.startsWith(FavoriteRoute().location)) return 1;
if (location.startsWith(SearchRoute().location)) return 2;
if (location.startsWith(SettingsRoute().location)) return 3;
if (location.startsWith(SearchRoute().location)) return 0;
if (location.startsWith(SettingsRoute().location)) return 2;
return 0;
}

Expand All @@ -33,8 +33,6 @@ class _AlgaNavigationBarState extends State<AlgaNavigationBar> {
case 1:
FavoriteRoute().go(context);
case 2:
SearchRoute().go(context);
case 3:
SettingsRoute().go(context);
default:
}
Expand All @@ -50,11 +48,6 @@ class _AlgaNavigationBarState extends State<AlgaNavigationBar> {
selectedIcon: const Icon(Icons.favorite_rounded),
label: context.tr.favorite,
),
NavigationDestination(
icon: const Icon(Icons.search_outlined),
selectedIcon: const Icon(Icons.search_rounded),
label: context.tr.search,
),
NavigationDestination(
icon: const Icon(Icons.settings_outlined),
selectedIcon: const Icon(Icons.settings),
Expand Down
11 changes: 7 additions & 4 deletions lib/ui/global.provider.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'dart:io';

import 'package:alga/utils/constants/import_helper.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

final isDesktop = StateProvider(
(ref) => Platform.isWindows || Platform.isLinux || Platform.isMacOS,
);
part 'global.provider.g.dart';

@Riverpod(keepAlive: true)
bool isDesktop(IsDesktopRef ref) {
return Platform.isWindows || Platform.isLinux || Platform.isMacOS;
}

0 comments on commit 70faac2

Please sign in to comment.