fix(android): pressing back button in any other tab other than home exits the app

This commit is contained in:
Kingkor Roy Tirtho 2024-02-18 23:02:14 +06:00
parent 86123456f2
commit c3289a0ba4
4 changed files with 44 additions and 37 deletions

View File

@ -1,6 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_desktop_tools/flutter_desktop_tools.dart'; import 'package:flutter_desktop_tools/flutter_desktop_tools.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.dart';

View File

@ -162,38 +162,47 @@ class RootApp extends HookConsumerWidget {
} }
} }
return Scaffold( return WillPopScope(
body: Sidebar( onWillPop: () async {
selectedIndex: rootPaths[location], if (rootPaths[location] != 0) {
onSelectedIndexChanged: onSelectIndexChanged, onSelectIndexChanged(0);
child: child, return false;
), }
extendBody: true, return true;
drawerScrimColor: Colors.transparent, },
endDrawer: DesktopTools.platform.isDesktop child: Scaffold(
? Container( body: Sidebar(
constraints: const BoxConstraints(maxWidth: 800), selectedIndex: rootPaths[location],
decoration: BoxDecoration( onSelectedIndexChanged: onSelectIndexChanged,
boxShadow: theme.brightness == Brightness.light child: child,
? null ),
: kElevationToShadow[8], extendBody: true,
), drawerScrimColor: Colors.transparent,
margin: const EdgeInsets.only( endDrawer: DesktopTools.platform.isDesktop
top: 40, ? Container(
bottom: 100, constraints: const BoxConstraints(maxWidth: 800),
), decoration: BoxDecoration(
child: const PlayerQueue(floating: true), boxShadow: theme.brightness == Brightness.light
) ? null
: null, : kElevationToShadow[8],
bottomNavigationBar: Column( ),
mainAxisSize: MainAxisSize.min, margin: const EdgeInsets.only(
children: [ top: 40,
BottomPlayer(), bottom: 100,
SpotubeNavigationBar( ),
selectedIndex: rootPaths[location], child: const PlayerQueue(floating: true),
onSelectedIndexChanged: onSelectIndexChanged, )
), : null,
], bottomNavigationBar: Column(
mainAxisSize: MainAxisSize.min,
children: [
BottomPlayer(),
SpotubeNavigationBar(
selectedIndex: rootPaths[location],
onSelectedIndexChanged: onSelectIndexChanged,
),
],
),
), ),
); );
} }

View File

@ -1014,10 +1014,10 @@ packages:
dependency: "direct main" dependency: "direct main"
description: description:
name: go_router name: go_router
sha256: "3b40e751eaaa855179b416974d59d29669e750d2e50fcdb2b37f1cb0ca8c803a" sha256: c5fa45fa502ee880839e3b2152d987c44abae26d064a2376d4aad434cf0f7b15
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "13.0.1" version: "12.1.3"
google_fonts: google_fonts:
dependency: "direct main" dependency: "direct main"
description: description:

View File

@ -55,7 +55,7 @@ dependencies:
flutter_svg: ^1.1.6 flutter_svg: ^1.1.6
form_validator: ^2.1.1 form_validator: ^2.1.1
fuzzywuzzy: ^1.1.6 fuzzywuzzy: ^1.1.6
go_router: ^13.0.1 go_router: 12.1.3 # Stuck on this https://github.com/flutter/flutter/issues/140869
google_fonts: ^6.1.0 google_fonts: ^6.1.0
hive: ^2.2.3 hive: ^2.2.3
hive_flutter: ^1.1.0 hive_flutter: ^1.1.0