Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter IconData未作为参数传递到类实例化中_Flutter_Dart - Fatal编程技术网

Flutter IconData未作为参数传递到类实例化中

Flutter IconData未作为参数传递到类实例化中,flutter,dart,Flutter,Dart,我定义了以下类: import 'package:flutter/material.dart'; class ItemHiddenMenu extends StatelessWidget { /// name of the menu item final String name; /// callback to recibe action click in item final Function onTap; final Color colorLineSelec

我定义了以下类:

    import 'package:flutter/material.dart';

class ItemHiddenMenu extends StatelessWidget {
  /// name of the menu item
  final String name;

  /// callback to recibe action click in item
  final Function onTap;

  final Color colorLineSelected;

  /// Base style of the text-item.
  final TextStyle baseStyle;

  /// style to apply to text when item is selected
  final TextStyle selectedStyle;

  final bool selected;

  final IconData icon;

  ItemHiddenMenu({
    Key key,
    this.name,
    this.selected = false,
    this.onTap,
    this.colorLineSelected = Colors.blue,
    this.baseStyle,
    this.selectedStyle,
    this.icon,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      margin: EdgeInsets.only(bottom: 15.0),
      child: InkWell(
        onTap: onTap,
        child: Row(
          children: <Widget>[
            ClipRRect(
              borderRadius: BorderRadius.only(
                  topRight: Radius.circular(4.0),
                  bottomRight: Radius.circular(4.0)),
              child: Container(
                height: 40.0,
                color: selected ? colorLineSelected : Colors.transparent,
                width: 5.0,
              ),
            ),
            Expanded(
              child: Container(
                margin: EdgeInsets.only(left: 20.0),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Icon(icon),
                    SizedBox(
                      width: 15,
                    ),
                    Text(
                      name,
                      style: (this.baseStyle ??
                              TextStyle(color: Colors.grey, fontSize: 25.0))
                          .merge(this.selected
                              ? this.selectedStyle ??
                                  TextStyle(color: Colors.white)
                              : null),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
代码运行正常,但图标不显示。出于测试目的,我尝试在类本身内部定义图标,它可以工作,但是我的所有实例都会有相同的图标,这不是我想要的


我在这里遗漏了什么?

我通过传递IconData尝试了您的代码。它可以工作,图标可见


您可以尝试传递和图标小部件,而不是IconData

我通过传递IconData尝试了您的代码。图标是可见的


您可以尝试传递和图标小部件,而不是IconData

这不是问题,他将其作为IconData传递并将其用作图标数据。我尝试过这样做,但我得到以下错误:“行的子项不能包含任何空值”,因此,我假设由于某种原因,参数分配不正确……那么错误在于其他方面。。行的子级为空。。使用堆栈跟踪记录完整堆栈跟踪。记录错误的原因是实际上没有引发任何错误。我只是看不到图标。@Imayadunandantanthats没问题,他正在将其作为IconData传递,并将其用作图标数据。我尝试过这样做,但我得到以下错误:“行的子行不能包含任何空值”,因此我假设由于某种原因参数分配不正确……那么错误在于其他方面。。行的子级为空。。使用堆栈跟踪记录完整堆栈跟踪。记录错误的原因是实际上没有引发任何错误。我就是看不到图标。@Imayadunandan
new ItemHiddenMenu(
          icon: Icons.dashboard,
          name: "Investments by category",
          baseStyle:
              TextStyle(color: Colors.white.withOpacity(0.8), fontSize: 20.0),
          colorLineSelected: Colors.teal,
        )