将数据从屏幕传递到抽屉抖动

时间:2020-02-07 14:56:13

标签: flutter

我想在仪表盘屏幕上将我的数据显示到抽屉中。我的仪表板屏幕从上一页接收到数据,我想将其中一些数据传递到我的抽屉中。

这是我的仪表板屏幕

class DashboardScreen extends StatefulWidget {
    final AuthUser user;
    DashboardScreen({Key key, this.user}) : super(key: key);

    @override
      _DashboardScreenState createState() => _DashboardScreenState();
 }

 class _DashboardScreenState extends State<DashboardScreen> {
     final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();

     @override
     Widget build(BuildContext context) {
       return Scaffold(
  key: _scaffoldKey,
  floatingActionButton: buildSpeedDial(),
  drawer: CollapsibleDrawer(),
  backgroundColor: Color(0xffeee9f1),
  body: Container(
      child: Column(
    children: <Widget>[
      Stack(
        children: <Widget>[
          ClipPath(
            clipper: DashboardClipper(),
            child: Container(
              decoration: BoxDecoration(
                  gradient: LinearGradient(colors: [
                Color(0xff6f3682).withOpacity(.8),
                Color(0xff9f44d3).withOpacity(.53),
              ], begin: Alignment.bottomCenter, end: Alignment.topCenter)),
              height: 48 * SizeConfig.heightMultiplier,
            ),
          ),
          Positioned(
              top: 40.0,
              child: Container(
                padding: EdgeInsets.only(left: 15.0, right: 15.0),
                width: MediaQuery.of(context).size.width,
                child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      IconButton(
                        icon: Icon(Icons.format_align_left,
                            color: Colors.white),
                        onPressed: () {
                          _scaffoldKey.currentState.openDrawer();
                        },
                      ),
                      Text(
                        'My Account',
                        style: TextStyle(
                            color: Colors.white,
                            fontWeight: FontWeight.w700),
                      ),
                      Column(
                        children: <Widget>[
                          CircleAvatar(
                            backgroundColor: Colors.brown.shade800,
                            child: Text('AH'),
                          ),
                        ],
                      )
                    ]),
              )),
           ]
         )
      )
     )]
  };

我的抽屉是一个有状态的小部件,看起来像这样

   return Drawer(
  // Add a ListView to the drawer. This ensures the user can scroll
  // through the options in the drawer if there isn't enough vertical
  // space to fit everything.
  child: Container(
    child: ListView(
      // Important: Remove any padding from the ListView.
      padding: EdgeInsets.zero,
      children: <Widget>[
        CustomPaint(
          painter: CurvePainter(),
          child: DrawerHeader(

            child: Row(
              children: <Widget>[
                CircleAvatar(
                  radius: 40,
                  // backgroundImage: AssetImage('assets/images/person.jpg'),
                ),
                SizedBox(
                  width: 20,
                ),
                Text(
                  '',
                  style: textStyle,
                )
              ],
            ),
          ),
        ),
        Column(children: <Widget>[]),
        ListTile(
          title: Text(
            'About Us',
            style: textStyleTile,
          ),
          trailing: Icon(
            Icons.wrap_text,
            color: Colors.black,
          ),
          onTap: () {},
        ),
        ListTile(
          title: Text(
            'SOS',
            style: textStyleTile,
          ),
          trailing: Icon(
            Icons.help,
            color: Colors.black,
          ),
          onTap: () {
            // Update the state of the app.
            // ...
          },
        ),
        ListTile(
          title: Text(
            'Share',
            style: textStyleTile,
          ),
          trailing: Icon(
            Icons.share,
            color: Colors.black,
          ),
          onTap: () {
            // Update the state of the app.
            // ...
          },
        ),
        ListTile(
          title: Text(
            'Settings',
            style: textStyleTile,
          ),
          trailing: Icon(
            Icons.settings,
            color: Colors.black,
          ),
          onTap: () {
            // Update the state of the app.
            // ...
          },
        ),
        SizedBox(
          height: MediaQuery.of(context).size.height / 11,
        ),
        Align(
          alignment: Alignment.bottomCenter,
          child: GestureDetector(
            onTap: () => print('tapped'),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  'Logout',
                  style: textStyleTile,
                ),
                Icon(
                  Icons.settings_power,
                  color: Colors.black,
                )
              ],
            ),
          ),
        )
      ],
    ),
  ),
);

opendrawer正在从仪表板屏幕打开抽屉。如何在抽屉中显示来自仪表板的数据?

1 个答案:

答案 0 :(得分:1)

将数据传递到CollapsibleDrawer构造函数。与将数据传递到DashboardScreen的构造函数的方式相同。

更改

drawer: CollapsibleDrawer(),

drawer: CollapsibleDrawer(user: this.user),