-
Notifications
You must be signed in to change notification settings - Fork 29.3k
Closed
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectfound in release: 3.16Found to occur in 3.16Found to occur in 3.16found in release: 3.19Found to occur in 3.19Found to occur in 3.19has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: flutter_adaptive_scaffoldThe flutter_adaptive_scaffold packageThe flutter_adaptive_scaffold packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Description
Steps to reproduce
- create a component using AdaptiveScaffold, leave useDrawer property unset (or set to true)
- run on desktop or web (as drawer is not used in mobile)
- make window smaller than smallBreakpoint so drawer is shown.
- use drawer to click any destination
Expected results
Drawer should close after clicking on a destination.
Actual results
Drawer does not close after clicking on a destination.
Although that seems the right approach for AdaptiveScaffold
, it could also provide a closeDrawer
method like Scaffold
. Sadly, even though AdaptiveScaffold
uses a Scaffold
internally, using Scaffold.of(context).closeDrawer()
does not work when used on onSelectedIndexChange
as the Scaffold context is a child of AdaptiveScaffold and so not found on the current context inside the handler.
Code sample
Code sample
import 'package:flutter/material.dart';
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
State<StatefulWidget> createState() => HomePageState();
}
class HomePageState extends State<HomePage> {
int selectedDestination = 0;
static const List<String> destinationLabels = <String>['Home', 'Settings'];
@override
Widget build(BuildContext context) {
return AdaptiveScaffold(
selectedIndex: selectedDestination,
destinations: <NavigationDestination>[
NavigationDestination(
icon: const Icon(Icons.home),
label: destinationLabels[0],
),
NavigationDestination(
icon: const Icon(Icons.settings),
label: destinationLabels[1],
),
],
body: (_) => Center(
child: Text(destinationLabels[selectedDestination]),
),
onSelectedIndexChange: (newDestination) {
setState(() {
selectedDestination = newDestination;
// The following line does not work as parent context does not contain a scaffold
// Scaffold.of(context).closeDrawer();
});
}
);
}
}
The example can be copied to DartPad to reproduce the bug.
Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.7, on macOS 14.2.1 23C71 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.2)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectfound in release: 3.16Found to occur in 3.16Found to occur in 3.16found in release: 3.19Found to occur in 3.19Found to occur in 3.19has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: flutter_adaptive_scaffoldThe flutter_adaptive_scaffold packageThe flutter_adaptive_scaffold packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team