Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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
Dart 颤振-压倒一切“;“建立”;CupertinoTabBar法_Dart_Flutter - Fatal编程技术网

Dart 颤振-压倒一切“;“建立”;CupertinoTabBar法

Dart 颤振-压倒一切“;“建立”;CupertinoTabBar法,dart,flutter,Dart,Flutter,我目前正试图定制Cupertinotabar小部件,方法是让我自己的类对其进行扩展并覆盖“build”方法。我当前的代码与此类似: class CustomTabBar extends CupertinoTabBar { CustomTabBar( Key key, @required List<BottomNavigationBarItem> items, ValueChanged<int> onTap, int currentInd

我目前正试图定制Cupertinotabar小部件,方法是让我自己的类对其进行扩展并覆盖“build”方法。我当前的代码与此类似:

class CustomTabBar extends CupertinoTabBar {
  CustomTabBar(
    Key key,
    @required List<BottomNavigationBarItem> items,
    ValueChanged<int> onTap,
    int currentIndex = 0,
    Color backgroundColor = _kDefaultTabBarBackgroundColor,
    Color activeColor = CupertinoColors.activeBlue,
    Color inactiveColor = CupertinoColors.inactiveGray,
    double iconSize = 30.0,
  ) : assert(items != null),
      super(items: items, onTap: onTap, currentIndex: currentIndex, 
        backgroundColor: backgroundColor, activeColor: activeColor, 
        inactiveColor: inactiveColor, iconSize: iconSize);

  @override
  Widget build(BuildContext context) {
    //build logic for the custom bar
  }
}
class CustomTabBar扩展了CupertinoTabBar{
自定义选项卡栏(
关键点,
@所需清单项目,
值更改为onTap,
int currentIndex=0,
颜色背景颜色=kDefaultTabBarBackgroundColor,
Color activeColor=CupertinoColors.activeBlue,
Color INACTIVEVECLOR=铜红色。inactiveGray,
双iconSize=30.0,
):assert(项!=null),
super(items:items,onTap:onTap,currentIndex:currentIndex,
backgroundColor:backgroundColor,activeColor:activeColor,
inactiveColor:inactiveColor,iconSize:iconSize);
@凌驾
小部件构建(构建上下文){
//为自定义栏构建逻辑
}
}
但是,当我运行应用程序时,调用的是Cupertinotabar构建方法,而不是CustomTabBar构建方法。换句话说,我的类并没有覆盖Cupertinotabar的构建


我有什么地方做错了吗?我这样做的原因是,我使用CupertinAbsCaffold为每个选项卡保留单独的导航器,CupertinAbsCaffold的tabBar参数只接受一个CupertinAbbar。

一般来说,Flatter更喜欢组合而不是继承。您试图通过此继承实现什么?

您需要重写copyWith方法

class CustomTabBar extends CupertinoTabBar {
  CustomTabBar(
    Key key,
    @required List<BottomNavigationBarItem> items,
    ValueChanged<int> onTap,
    int currentIndex = 0,
    Color backgroundColor = _kDefaultTabBarBackgroundColor,
    Color activeColor = CupertinoColors.activeBlue,
    Color inactiveColor = CupertinoColors.inactiveGray,
    double iconSize = 30.0,
  ) : assert(items != null),
      super(items: items, onTap: onTap, currentIndex: currentIndex, 
        backgroundColor: backgroundColor, activeColor: activeColor, 
        inactiveColor: inactiveColor, iconSize: iconSize);

  @override
  Widget build(BuildContext context) {
    //build logic for the custom bar
  }

  @override
  CustomTabBar copyWith({
    Key key,
    List<BottomNavigationBarItem> items,
    Color backgroundColor,
    Color activeColor,
    Color inactiveColor,
    Size iconSize,
    Border border,
    int currentIndex,
    ValueChanged<int> onTap,
  }) {
    return CustomTabBar(
      key: key ?? this.key,
      items: items ?? this.items,
      backgroundColor: backgroundColor ?? this.backgroundColor,
      activeColor: activeColor ?? this.activeColor,
      inactiveColor: inactiveColor ?? this.inactiveColor,
      iconSize: iconSize ?? this.iconSize,
      border: border ?? this.border,
      currentIndex: currentIndex ?? this.currentIndex,
      onTap: onTap ?? this.onTap
    );
  }
}
class CustomTabBar扩展了CupertinoTabBar{
自定义选项卡栏(
关键点,
@所需清单项目,
值更改为onTap,
int currentIndex=0,
颜色背景颜色=kDefaultTabBarBackgroundColor,
Color activeColor=CupertinoColors.activeBlue,
Color INACTIVEVECLOR=铜红色。inactiveGray,
双iconSize=30.0,
):assert(项!=null),
super(items:items,onTap:onTap,currentIndex:currentIndex,
backgroundColor:backgroundColor,activeColor:activeColor,
inactiveColor:inactiveColor,iconSize:iconSize);
@凌驾
小部件构建(构建上下文){
//为自定义栏构建逻辑
}
@凌驾
CustomTabBar copyWith({
关键点,
清单项目,
颜色背景颜色,
颜色activeColor,
颜色,
尺寸图标化,
边界,,
int currentIndex,
值更改为onTap,
}) {
返回自定义选项卡栏(
钥匙:钥匙??这个。钥匙,
项目:项目??此。项目,
背景色:背景色??这个背景色,
activeColor:activeColor??this.activeColor,
inactiveColor:inactiveColor??此。inactiveColor,
iconSize:iconSize??这个,
边界:边界??这个边界,
currentIndex:currentIndex??此.currentIndex,
onTap:onTap??this.onTap
);
}
}

您能从覆盖的方法中粘贴代码吗?我试图构建一个自定义导航栏,并在一个只接受CupertinoTabBar的Cupertinotabspafold中使用它。然而,我对堆栈和定位小部件使用了不同的方法。为什么只有在重写
copyWith
方法时才起作用?