【问题标题】:Flutter Image AppBar Extend further than backgroundFlutter Image AppBar 比背景扩展得更远
【发布时间】:2022-01-09 04:42:04
【问题描述】:

我的问题是如何将透明图像扩展得比应用栏的边框更远?我希望图像覆盖整个应用栏,我尝试过使用 fit: 但它不起作用。我想要图像覆盖的整个橙色。

下面是我的代码:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var title = 'Web Images';

return MaterialApp(
  title: title,
  home: Scaffold(
    appBar: AppBar(
      title: SizedBox(
        width: 1000,
        child: Image.asset('assets/images/foodBackground.png'),


         ),
            backgroundColor: const Color(0xffFA7343),
        ),
        body: Text('test1'),
      ),
    );
  }
}

This is the image of how it looks, as you can see it hasn't filled to the edges of the appbar.

【问题讨论】:

    标签: flutter android-studio dart


    【解决方案1】:
    AppBar(
      flexibleSpace: Image.asset(
        'assets/images/foodBackground.png',
      ),
    ),
    

    【讨论】:

      【解决方案2】:

      试试这个,你需要确保titleSpacing 应该为零并且你的动态宽度ouble.infinity

      AppBar(
                titleSpacing: 0,
                title: SizedBox(
                  width: double.infinity,
                  child: Image.asset('assets/images/test.jpg'),
                ),
                backgroundColor: const Color(0xffFA7343),
              )
      

      输出:

      【讨论】:

        猜你喜欢
        • 2018-10-28
        • 2021-05-24
        • 2019-01-15
        • 1970-01-01
        • 2021-04-16
        • 1970-01-01
        • 2020-08-21
        • 2020-12-09
        相关资源
        最近更新 更多