我只在上一堂课时才尝试drawer
在课堂上做一个。为此,我创建了一个变量 String并将该变量传递给 class 。但是,我很难编写 if-else 语句来仅当 String等于.DetailedPage
CameraPage
previousScreen = 'CAMERA'
DetailedPage
drawer
previousScreen
'CAMERA'
我遵循了此页面上的建议,但它没有工作,因为我想使用drawer: MyDrawer()
。(drawer:
似乎它有一个指定的地方,例如在bewteen Scaffold
and CustomScrollView
, to work)。有什么方法可以使用 if-else 语句drawer: MyDrawer()
吗?
我的全部DetailedPage
在这里:(我试图削减一些不必要的代码,所以括号的数量可能不对,但除了最后的 if-else 语句之外,它都有效。)
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: <Widget>[
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: <Widget>[
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,
);
}
}