1

我一直在尝试创建带有一些导航按钮的背景菜单,每个按钮都有自己的无状态小部件页面。我想根据单击菜单的索引位置传递子小部件页面。

需要根据后层的菜单动作更新前层

后台菜单列表。

backlayer.dart

    class BackLayer extends StatefulWidget {
  AnimationController controller;
  Widget child;
  BackLayer({this.controller});

  _BackLayerState createState() => _BackLayerState();
}

class _BackLayerState extends State<BackLayer> {
  var _currentPageIndex;
  List<String> navlist = ['Home', 'About', 'Contact Us'];
  bool get isPanelVisible {
    final AnimationStatus status = widget.controller.status;
    return status == AnimationStatus.completed ||
        status == AnimationStatus.forward;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView.builder(
              itemCount: navlist.length,
              itemBuilder: (BuildContext context, int index) {
                return Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    ListTile(
                      onTap: () {
                        setState(() {
                          _currentPageIndex = navlist[index];
                        });
                        // PanelClass(frontLayer: About(),);
                        print(navlist[index].toString());

                        widget.controller
                            .fling(velocity: isPanelVisible ? -1.0 : 1.0);
                      },
                      title: Text(
                        navlist[index],
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            color: Colors.black87, fontWeight: FontWeight.bold),
                      ),
                    )
                  ],
                );

我想在背景.dart 中传递单击菜单的引用,我将在其中将该引用传递给 panelClass body 作为子级。

背景.dart

    class BackDrop extends StatefulWidget {

  _BackDropState createState() => _BackDropState();
}

class _BackDropState extends State<BackDrop> with TickerProviderStateMixin {
  AnimationController controller;

  @override
  void initState() {
    super.initState();
    controller = AnimationController(
        duration: Duration(seconds: 3), vsync: this, value: 1.0);
  }

  @override
  void dispose() {
    super.dispose();
    controller.dispose();
  }

  bool get isPanelVisible {
    final AnimationStatus status = controller.status;
    return status == AnimationStatus.completed ||
        status == AnimationStatus.forward;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        backgroundColor: Theme.of(context).accentColor,
        title: Text('Home'),
        leading: IconButton(
          onPressed: () {
            controller.fling(velocity: isPanelVisible ? -1.0 : 1.0);
          },
          icon: AnimatedIcon(
            progress: controller.view,
            icon: AnimatedIcons.close_menu,
          ),
        ),
      ),
      body: PanelClass(controller: controller,frontLayer: 'Need to get reference here',),
    );
  }
}
4

0 回答 0