我试图将我的menuButton类别名称传递给下一页,并在我的categoryScreens上设置下一页的状态。

当前,我收到一条红色的波浪线,并带有“不能将参数类型'Context'分配给参数类型'BuildContext'的注释”

import 'package:flutter/material.dart';
import 'package:boardwalk/Screens/categoryScreen.dart';
import 'package:boardwalk/Widgets/headerCategory.dart';
import 'package:path/path.dart';

class homeMenu extends StatelessWidget {
  const homeMenu({Key key}) : super(key: key);
  Padding menuButton(String category, IconData categoryIcon) {
    return Padding(
        padding: const EdgeInsets.symmetric(horizontal: 10),
        child: Container(
          width: 95,
          child: InkWell(
            onTap: ()=>
              Navigator.of(context).push(MaterialPageRoute(builder: (context) => categoryScreen()));
            ,
            child: Column(
              children: <Widget>[
                Center(
                  child: Container(
                    height: 70,
                    width: 70,
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        colors: [Colors.deepPurple, Colors.deepPurpleAccent],
                      ),
                      shape: BoxShape.circle,
                    ),
                    child: Icon(
                      categoryIcon,
                      size: 40.0,
                      color: Colors.white,
                    ),
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.all(6.0),
                  child: Text(
                    category,
                    style: TextStyle(
                      color: Colors.deepPurpleAccent,
                      fontSize: 14,
                    ),
                  ),
                )
              ],
            ),
          ),
        ));
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(top: 8.0),
      child: Container(
        height: 100,
        width: 400,
        child: ListView(scrollDirection: Axis.horizontal, children: <Widget>[
          menuButton('Home', Icons.home),
          menuButton('Eat', Icons.restaurant_menu),
          menuButton('Shop', Icons.store),
          menuButton('Travel', Icons.airplanemode_active),
          menuButton('Play', Icons.local_activity),
          menuButton('Service', Icons.build),
        ]),
      ),
    );
  }
}

我不确定在导航器中传递的内容是否与上下文无关,我不确定在这一点上会发生什么。

最佳答案

实际上,此问题是由导入path.dart包引起的。要解决此问题,请将上下文更改为this.context

10-01 21:03