Flutter: 如何编写if-else语句以调用抽屉?
Flutter: 如何编写if-else语句以调用抽屉?
我正在尝试仅在前一个类为CameraPage
时,在类DetailedPage
中创建一个drawer
。为了实现这一点,我创建了一个变量StringpreviousScreen =\'CAMERA\'
,并将变量传递给类DetailedPage
。然而,我在编写if-else语句时遇到了困难,只有当StringpreviousScreen
等于\'CAMERA\'
时才能制作drawer
。
我按照此页面的建议去做,但它没有起作用,因为我想使用drawer:MyDrawer()
。(drawer:
似乎有一个指定的位置,如在Scaffold
和CustomScrollView
之间,才能起作用)。有没有办法为drawer:MyDrawer()
编写if-else语句?
我整个的DetailedPage
在这里:
class DetailScreen extends StatelessWidget { final Recyclable recyclable; final String previousScreen; DetailScreen( {Key key, @required this.recyclable, @required this.previousScreen}) : super(key: key); @override Widget build(BuildContext context) { //set variables String imagename = recyclable.title; String recycle = recyclable.recycle; String instruction = recyclable.instruction; String why = recyclable.why; String donate = recyclable.donate; return Scaffold( body: CustomScrollView( physics: const BouncingScrollPhysics(), slivers: [ SliverAppBar( expandedHeight: 200.0, pinned: false, floating: false, backgroundColor: Colors.transparent, onStretchTrigger: () { // Function callback for stretch return; }, flexibleSpace: FlexibleSpaceBar( centerTitle: true, title: Text('$imagename', style: TextStyle( fontSize: 55.0, fontFamily: 'Rajdhani', fontWeight: FontWeight.w700, color: Colors.white)), background: Container( decoration: MyBoxDecoration(imagename), ), ), actions: [ IconButton( icon: Icon( Icons.widgets, color: Colors.white, ), tooltip: 'Home Page', //show side pages onPressed: () => Navigator.of(context).pushNamed('/HOME'), ), ], ), SliverPadding( padding: EdgeInsets.all(20.0), sliver: SliverList( delegate: SliverChildListDelegate([ Row( children: [ Text('This item is ', style: LightThemeGrey().textTheme.bodyText1), Text('$recycle', style: LightThemeGrey().textTheme.subtitle2), Text('.', style: LightThemeGrey().textTheme.bodyText1), ], ), ]), ), ), ], ); //TODO: If previous Screen == CAMERA, make MyDrawer() previousScreen == 'CAMERA'? drawer: MyDrawer() : null, ); } }
admin 更改状态以发布 2023年5月21日