'how to add one more drawer inside a drawer in flutter?
strong text When I pressed on setting in drawer and then open a new drawer. How to implement a drawer when I click on button in a drawer.
| image1 | image2 |
|---|---|
![]() |
![]() |
Solution 1:[1]
This might be late but another solution is building a Scaffold & an AppBar inside Drawer, and taking advantage of the build-in navigation behavior.
Note the following example uses Builder to open a Drawer programmatically, you can also use GlobalKey.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MultiDrawers(),
);
}
}
class MultiDrawers extends StatelessWidget {
const MultiDrawers({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(backgroundColor: Colors.teal),
drawer: const FirstDrawer(),
body: const Center(child: Text('multi-layer drawer example')),
);
}
}
class FirstDrawer extends StatelessWidget {
const FirstDrawer({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Drawer(
child: Scaffold(
appBar: AppBar(
title: const Text('1st drawer'),
automaticallyImplyLeading: false, // hide hamburger icon
),
drawer: const SecondDrawer(),
body: Center(
child: Builder(builder: (context) {
return ElevatedButton(
onPressed: () {
Scaffold.of(context).openDrawer();
},
child: const Text('open 2nd drawer'),
);
}),
),
),
);
}
}
class SecondDrawer extends StatelessWidget {
const SecondDrawer({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('2nd drawer'),
backgroundColor: Colors.pink,
),
body: const Center(
child: Text('this is 2nd drawer'),
),
);
}
}
Solution 2:[2]
I think I see it.
The code can be reformatted as:
condition = \
(share_data_sm[yr]['MC']!='MA') & \
(share_data_sm[yr]['MC']!=' ') & \
(share_data_sm[yr]['MY']!=' ')
val_if_true = share_data_sm[yr]['MC'].astype(str) + share_data_sm[yr]['N'].astype(str) + share_data_sm[yr]['MFR'].astype(str)
val_if_false = share_data_sm[yr]['MFR']
share_data_sm[yr]['MMR'] = np.where(condition, val_if_true, val_if_false)
Now you can see that the value types of val_if_true and val_if_false are different - in the first case, you add together 3 str values. In the second, you're keeping the datatype of share_data_sm[yr]['MFR'].
I bet it complains when you try to add both types into the same array.
Solution 3:[3]
The traceback says the error is in the complicated
np.where((share_data_sm[yr]['MC']!='MA') & (share_data_sm[yr]['MC']!=' ') & (share_data_sm[yr]['MY']!=' '), share_data_sm[yr]['MC'].astype(str) + share_data_sm[yr]['N'].astype(str) + share_data_sm[yr]['MFR'].astype(str), share_data_sm[yr]['MFR'])
But keep in mind that it has to evaluate each of the 3 arguments before passing them to where.
(share_data_sm[yr]['MC']!='MA') & (share_data_sm[yr]['MC']!=' ') & (share_data_sm[yr]['MY']!=' ')
share_data_sm[yr]['MC'].astype(str) + share_data_sm[yr]['N'].astype(str) + share_data_sm[yr]['MFR'].astype(str)
share_data_sm[yr]['MFR']
It's a little hard to read the traceback, but the str+ error suggests it in the middle argument. But you are adding string values.
But I am seeing this.join and indices which suggests that it's trying to line up the indices of the series. So frame indices may be mostly strings, with an oddball numeric index. But this is just a guess; I'm not a pandas expert.
I'd suggest evaluating those 3 arguments before hand, before using them in the where to better isolate the problem. Expressions that extend over many lines are hard to debug.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Wenhui Luo |
| Solution 2 | Morton |
| Solution 3 | hpaulj |



