через несколько дней, чтобы решить эту проблему, я не могу
Я внедрил простой блочный шаблон в свое приложение и хочу открыть Drawer
, нажав FloatingActionButton
или значок Icons.menu
,но мой код
Scaffold.of(context).openDrawer();
не работает
мой код:
return Scaffold(
body: BlocBuilder<HomeEvent, HomeState>(
bloc: _homeBloc,
builder: (BuildContext context, HomeState state) {
Scaffold.of(context).openDrawer(); //<---- don't work
if (state is HandleDrawerMenuClick) {
_onWidgetDidBuild(() {
Scaffold.of(context).openDrawer(); //<---- don't work
_showToast(context); //<---- work fine
});
}
return WillPopScope(
onWillPop: () {
customPop(context);
},
child: Directionality(
textDirection: TextDirection.rtl,
child: Scaffold(
primary: true,
appBar: ApplicationToolbar(homeBloc: _homeBloc),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
Scaffold.of(context).openDrawer(); //<---- don't work
_showToast(context); //<---- work fine
},
),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: AppBottomNavigationBar(),
drawer: AppDrawer(),
body: _fragments[_currentIndex],
),
),
);
}),
);
HomeEvent
класс:
class HomeEvent extends Equatable{
HomeEvent([List props = const []]) : super(props);
}
class OnDrawerMenuClicked extends HomeEvent {
@override
String toString() => 'OnDrawerMenuClicked clicked';
}
class OnDrawerMenuItemsClicked extends HomeEvent {
var onItem = 1;
OnDrawerMenuItemsClicked({this.onItem});
@override
String toString() => 'OnDrawerMenuItemsClicked clicked';
}
HomeState
класс:
class HomeState extends Equatable{
HomeState([List props = const[]]):super(props);
}
class HomeInitial extends HomeState{
@override
String toString()=>'HomeInitial';
}
class HandleDrawerMenuClick extends HomeState{
@override
String toString()=>'HandleDrawerMenuClick';
}