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!
Steps to reproduce
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 acloseDrawermethod likeScaffold. Sadly, even thoughAdaptiveScaffolduses aScaffoldinternally, usingScaffold.of(context).closeDrawer()does not work when used ononSelectedIndexChangeas the Scaffold context is a child of AdaptiveScaffold and so not found on the current context inside the handler.Code sample
Code sample
The example can be copied to DartPad to reproduce the bug.
Screenshots or Video
No response
Logs
No response
Flutter Doctor output
Doctor output