Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/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
Flutter 有没有办法使选项卡栏指示线在颤振中成为梯度?_Flutter_Flutter Layout - Fatal编程技术网

Flutter 有没有办法使选项卡栏指示线在颤振中成为梯度?

Flutter 有没有办法使选项卡栏指示线在颤振中成为梯度?,flutter,flutter-layout,Flutter,Flutter Layout,我正在尝试创建一个具有渐变下划线的选项卡栏,如下图所示。 我试着使用一个盒子装饰,正如前面的帖子所建议的,但它并没有完全按照我想要的那样显示出来 TabBar( labelColor: Theme.of(context).primaryColor, indicator: BoxDecoration( gradient: LinearGradient( colors: const [Color(0xFF10C7E0), Color(0xFF

我正在尝试创建一个具有渐变下划线的选项卡栏,如下图所示。

我试着使用一个盒子装饰,正如前面的帖子所建议的,但它并没有完全按照我想要的那样显示出来

TabBar(
        labelColor: Theme.of(context).primaryColor,
        indicator: BoxDecoration(
          gradient: LinearGradient(
  colors: const [Color(0xFF10C7E0), Color(0xFF00D5C3)],
),
        ),
        tabs: ...,
      ),
当我尝试时,我得到的是


有人指出,这篇文章是10个月前发表的文章的翻版。但是,在那里说明的方法不再有效。是的,我试过了。

试着用这样的东西代替它:

指标:集装箱( 对齐:对齐.bottomCenter, 子:容器( 身高:8.0 装饰:盒子装饰(…) )


从我的IPhone发布此选项有什么问题?(基于链接中的代码)

导入“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
debugShowCheckedModeBanner:false,
主页:DefaultTabController(
长度:2,
孩子:脚手架(
appBar:appBar(
标题:文本(“全部”,样式:TextStyle(颜色:常量颜色(0xff596173)),
背景颜色:Colors.white,
标题:对,
底部:选项卡栏(
labelColor:const Color(0xff525c6e),
未选择的标签颜色:常量颜色(0xffacb3bf),
指示灯添加:所有边缘设置(0.0),
指示器重量:4.0,
标签填充:仅限边集(左:0.0,右:0.0),
指标:形状装饰(
形状:下划线输入边框(
borderSide:borderSide(颜色:Colors.transparent,宽度:0,样式:BorderStyle.solid)),
渐变:线性渐变(颜色:[颜色(0xff0081ff),颜色(0xff01ff80)]),
选项卡:[
容器(
身高:40,
对齐:对齐.center,
颜色:颜色,白色,
子项:文本(“视觉”),
),
容器(
身高:40,
对齐:对齐.center,
颜色:颜色,白色,
子项:文本(“表格”),
),
],
),
),
主体:容器(颜色:Colors.grey[200]),
),
),
);
}
}

第二个答案的可能重复项在不更改核心文件的情况下回答了它。该解决方案不起作用?这不起作用,因为指示器只接受长方体装饰或FlatterLogo装饰或ShapeDecoration或UnderlineTabindItator,然后您可以使用UnderlineTabindItator吗?否则,与Flatter一样,您可以实现您自己的选项卡小部件。“本机”小部件仅实现材料设计和人机界面准则。当您查看本机实现并从中提取您自己的小部件时,自定义设计可以轻松实现。谢谢。我发现了我的错误,我在tabs属性中使用了选项卡小部件,而不是容器。
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            title: Text('All', style: TextStyle(color: const Color(0xff596173))),
            backgroundColor: Colors.white,
            centerTitle: true,
            bottom: TabBar(
              labelColor: const Color(0xff525c6e),
              unselectedLabelColor: const Color(0xffacb3bf),
              indicatorPadding: EdgeInsets.all(0.0),
              indicatorWeight: 4.0,
              labelPadding: EdgeInsets.only(left: 0.0, right: 0.0),
              indicator: ShapeDecoration(
                  shape: UnderlineInputBorder(
                      borderSide: BorderSide(color: Colors.transparent, width: 0, style: BorderStyle.solid)),
                  gradient: LinearGradient(colors: [Color(0xff0081ff), Color(0xff01ff80)])),
              tabs: <Widget>[
                Container(
                  height: 40,
                  alignment: Alignment.center,
                  color: Colors.white,
                  child: Text("Visual"),
                ),
                Container(
                  height: 40,
                  alignment: Alignment.center,
                  color: Colors.white,
                  child: Text("Tabular"),
                ),
              ],
            ),
          ),
          body: Container(color: Colors.grey[200]),
        ),
      ),
    );
  }
}