如何使背景图像定位

Mahmut Can Kurt

当我在下面与您共享的main.dart文件中写入背景图像代码时,我要使用的数据保留在“图像”下。我怎么解决这个问题?我知道我在错误的位置写了有关Background的部分,但我不知道在哪里写。感谢您的帮助。

@override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Weather App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
          backgroundColor: Colors.tealAccent,
          appBar: AppBar(
            title: Text('Flutter Weather App'),
          ),
          body: Center(
              child: Column(children: <Widget>[
            //WEATHER DATA
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: weatherData != null
                        ? Weather(weather: weatherData)
                        : Container(),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: isLoading
                        ? CircularProgressIndicator(
                            strokeWidth: 2.0,
                            valueColor:
                                new AlwaysStoppedAnimation(Colors.black),
                          )
                        : IconButton(
                            icon: new Icon(Icons.refresh),
                            tooltip: 'Refresh',
                            onPressed: () async {
                              await loadWeather();
                            },
                            color: Colors.black,
                          ),
                  ),
                ],
              ),
            ),

            //BACKGROUND IMAGE
            Container(
              height: 501.7,
              width: 420.0,
              decoration: BoxDecoration(
                image: DecorationImage(
                  image: isweatherDataLoaded //this
                      ? HandleError()
                      : images["clear"],
                  fit: BoxFit.fill,
                ),
                shape: BoxShape.rectangle,
              ),
            ),

            //FUTURE FORECAST WEATHER DATA
            SafeArea(
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Container(
                  height: 200.0,
                  child: forecastData != null
                      ? ListView.builder(
                          itemCount: forecastData.list.length,
                          scrollDirection: Axis.horizontal,
                          itemBuilder: (context, index) => WeatherItem(
                              weather: forecastData.list.elementAt(index)))
                      : Container(),
                ),
              ),
            )
          ]))),
    );
  }

无论我在哪里写,都没有用。我想让你给我看看。如果您愿意,我可以与您分享其余的代码。祝您满意!谢谢..

迈克尔·S

我建议将带有背景图像的容器在层次结构中向上移动,如下所示:

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Weather App',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
          backgroundColor: Colors.tealAccent,
          appBar: AppBar(
            title: Text('Flutter Weather App'),
          ),
          body: Container(
            height: 501.7,
            width: 420.0,
            decoration: BoxDecoration(
              image: DecorationImage(
                image: isweatherDataLoaded //this
                    ? HandleError()
                    : images["clear"],
                fit: BoxFit.fill,
              ),
              shape: BoxShape.rectangle,
            ),
            child: Center(
                child: Column(children: <Widget>[
                  //WEATHER DATA
                  Expanded(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: <Widget>[
                        Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: weatherData != null
                              ? Weather(weather: weatherData)
                              : Container(),
                        ),
                        Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: isLoading
                              ? CircularProgressIndicator(
                            strokeWidth: 2.0,
                            valueColor:
                            new AlwaysStoppedAnimation(Colors.black),
                          )
                              : IconButton(
                            icon: new Icon(Icons.refresh),
                            tooltip: 'Refresh',
                            onPressed: () async {
                              await loadWeather();
                            },
                            color: Colors.black,
                          ),
                        ),
                      ],
                    ),
                  ),
                  //FUTURE FORECAST WEATHER DATA
                  SafeArea(
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Container(
                        height: 200.0,
                        child: forecastData != null
                            ? ListView.builder(
                            itemCount: forecastData.list.length,
                            scrollDirection: Axis.horizontal,
                            itemBuilder: (context, index) => WeatherItem(
                                weather: forecastData.list.elementAt(index)))
                            : Container(),
                      ),
                    ),
                  )
                ])),
          )),
    );
  }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何定位图像使其与背景图像重叠

来自分类Dev

定位多个背景图像

来自分类Dev

如何定位文本,使其不会沿着背景图像移动?

来自分类Dev

如何在reveal.js中定位背景图像?

来自分类Dev

如何定位文本,使其不会沿着背景图像移动?

来自分类Dev

定位后裁剪背景图像

来自分类Dev

定位后裁剪背景图像

来自分类Dev

定位/调整背景图像的问题

来自分类Dev

如何在背景图像上相对于图像定位 UI 元素

来自分类Dev

如何淡化背景图像

来自分类Dev

如何淡化背景图像

来自分类Dev

如何使背景图像响应?

来自分类Dev

如何相对于背景图像宽度定位元素

来自分类Dev

如何将元素定位到背景图像上的精确点?

来自分类Dev

如何相对于背景图像宽度定位元素

来自分类Dev

如何使图像充满背景图像?

来自分类Dev

使背景图像适合屏幕并将其定位到底部

来自分类Dev

固定位置时iOS移动背景图像

来自分类Dev

jQuery悬停以固定位置更改背景图像

来自分类Dev

如何.animate()背景图像大小

来自分类Dev

如何使背景图像的黑色部分透明?

来自分类Dev

如何使背景图像不可拉伸?

来自分类Dev

如何更改离子的背景图像?

来自分类Dev

如何使div背景图像响应

来自分类Dev

如何获得透明的背景图像重复

来自分类Dev

如何模糊背景图像的“重复”部分?

来自分类Dev

如何裁剪不拉伸背景图像

来自分类Dev

如何使CSS背景图像响应?

来自分类Dev

如何淡出循环背景图像?