Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/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
Image 使用带有颤振的永久背景图像_Image_User Interface_Flutter - Fatal编程技术网

Image 使用带有颤振的永久背景图像

Image 使用带有颤振的永久背景图像,image,user-interface,flutter,Image,User Interface,Flutter,我正在开发一个具有2个选项卡视图的应用程序,希望在能够在2个选项卡之间滑动或导航的情况下获得永久性背景图像。以下是小部件的代码: class MyTabs extends StatefulWidget { @override MyTabsState createState() => new MyTabsState(); } class MyTabsState extends State<MyTabs> with SingleTickerProviderStateMix

我正在开发一个具有2个选项卡视图的应用程序,希望在能够在2个选项卡之间滑动或导航的情况下获得永久性背景图像。以下是小部件的代码:

class MyTabs extends StatefulWidget {
  @override
  MyTabsState createState() => new MyTabsState();
}

class MyTabsState extends State<MyTabs> with SingleTickerProviderStateMixin {

  TabController controller;

  @override
  void initState() {
    super.initState();
    controller = new TabController(length: 2, vsync: this);
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Divot', style: new TextStyle(fontFamily: 'Pacifico')),
        centerTitle: true,
        backgroundColor: Colors.green,
        bottom: new TabBar(
          controller: controller,
            tabs: <Tab>[
              new Tab(icon: new Icon(Icons.golf_course)),
              new Tab(icon: new Icon(Icons.account_circle)),
            ]),
      ),
      body: new Stack(
        children: <Widget>[
          new Container(
            decoration: new BoxDecoration(
              image: new DecorationImage(image: new AssetImage("image"), fit: BoxFit.fill,),
            ),
          ),
          new TabBarView(
            controller: controller,
              children: <Widget>[
                new second.GameMenu(),
                new third.MyProfilePage(),
              ],
          )
        ],
      )
    );
  }
}
类MyTabs扩展StatefulWidget{
@凌驾
MyTabsState createState()=>新建MyTabsState();
}
类MyTabsState使用SingleTickerProviderStateMixin扩展状态{
tab控制器;
@凌驾
void initState(){
super.initState();
控制器=新的TabController(长度:2,vsync:this);
}
@凌驾
无效处置(){
controller.dispose();
super.dispose();
}
@凌驾
小部件构建(构建上下文){
归还新脚手架(
appBar:新的appBar(
标题:新文本('Divot',样式:新文本样式(fontFamily:'Pacifico')),
标题:对,
背景颜色:Colors.green,
底部:新选项卡栏(
控制器:控制器,
选项卡:[
新建选项卡(图标:新建图标(图标.高尔夫球场)),
新建选项卡(图标:新建图标(图标.帐户\圆圈)),
]),
),
正文:新堆栈(
儿童:[
新容器(
装饰:新盒子装饰(
图像:新装饰图像(图像:新资产估计(“图像”),适合:BoxFit.fill,),
),
),
新选项卡视图(
控制器:控制器,
儿童:[
新建第二个.GameMenu(),
新建第三个.MyProfilePage(),
],
)
],
)
);
}
}

没有错误,但第一个选项卡上有白色背景,第二个选项卡上有AssetImage背景。我遗漏了什么?

在Android中,这会容易得多,只需在XML文件中设置background属性,就这么简单


在flatter中,我建议在Scaffold的
body
属性中,在
TabBarView
子对象中,您可以尝试传递具有背景的小部件。或者尝试将大多数小部件的
backgroundColor
属性设置为
Colors.transparent

我知道这是个老问题,但以防万一

通过使用容器作为脚手架主体,并使TabBarView成为容器的子对象,我获得了您想要的效果。然后你可以使用

decoration: BoxDecoration(
            image: DecorationImage(
              image:
                  AssetImage("some image path"),
              fit: BoxFit.cover,
              colorFilter: ColorFilter.mode(
                  Colors.black.withOpacity(0.4), BlendMode.dstATop),
要创建显示在每个选项卡视图上的背景,请执行以下操作:-)