自定义导航到单独的按钮,以便它可以访问不同的屏幕

customize navigation to seperate button so that it can access to different screen

我已经创建了一个单独的按钮小部件,这样我就可以通过更改名称和导航来访问我需要的所有其他屏幕,但我不知道如何添加导航来为不同的屏幕自定义名称

class GlowingButton extends StatefulWidget {
    final Color color1;
    final Color color2;

    const GlowingButton({
    Key key,
    this.color1 = Colors.brown,
    this.color2 = Colors.white10,
    this.buttonName,
    this.routeName,
    }) : super(key: key);
    final String buttonName;
    final  routeName;
    @override
    _GlowingButtonState createState() => _GlowingButtonState();
    }

    class _GlowingButtonState extends State<GlowingButton> {
    var glowing = true;
    var scale = 1.0;
    @override
  Widget build(BuildContext context) {
    SizeConfig().init(context);
    return GestureDetector(
      onTapUp: (val)async {
        setState(() {
          glowing = false;
          scale = 1.0;
        });
      },
      onTapDown: (val)async {
        setState(() {
          glowing = true;
          scale = 1.1;
        });
       onTapDown: (val) async {
        setState(() {
          glowing = true;
          scale = 1.1;
        });
        await Future.delayed(
          Duration(milliseconds: 300),
        );
        await Navigator.pushNamed(context,  MyRoute.(widget.routeName));
        setState(
          () {},
        );
      },
}

GlowingButton

上添加功能
class GlowingButton extends StatefulWidget {
  final Color color1;
  final Color color2;
  final Function onTapDown;


.......

  onTapDown: (val) async {
        setState(() {
          glowing = true;
          scale = 1.1;
        });
        // await Future.delayed(
        //   Duration(milliseconds: 300),
        // );
        // await Navigator.pushNamed(context,  MyRoute.(widget.routeName));

        await widget.onTapDown();
        setState(
          () {},
        );
      },

并使用

  GlowingButton(onTapDown: ()async{},...)

此外,您可以通过完整的 routeName 并使用您所做的方式

await Navigator.pushNamed(context, "${widget.fullRouteName}"); // 如果你有什么要补充的 routeName 请关注 value${variable}.

你的情况解决了吗?