【问题标题】:Normal Appbar with image background in FlutterFlutter中带有图像背景的普通Appbar
【发布时间】:2020-08-21 08:49:36
【问题描述】:

我是新来的。如果这个问题很奇怪,请不要介意。我需要 AppBar 中的背景图片。我在互联网上找到了一个小部件 SliverAppBar 的解决方案。我需要正常出现的图像背景图像。我发现 AppBar 中没有图像或背景图像的属性。谁能帮我这个?
谢谢!达山。

【问题讨论】:

标签: flutter dart appbar


【解决方案1】:

欢迎使用 stackoverflow。
为了理解,我之前做了这个演示。请按照以下示例代码进行操作。

import 'package:flutter/material.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: AppBarWithImage(),
    );
  }
}

class AppBarWithImage extends StatefulWidget {
  @override
  _AppBarWithImageState createState() => _AppBarWithImageState();
}

class _AppBarWithImageState extends State<AppBarWithImage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('App Bar with image background'),
        flexibleSpace: Image(
          image: NetworkImage(
            "https://images.pexels.com/photos/396547/pexels-photo-396547.jpeg?auto=compress&cs=tinysrgb&h=350",
          ),
          fit: BoxFit.cover,
        ),
        backgroundColor: Colors.transparent,
      ),
      body: Center(
        child: Text("Sample Text"),
      ),
    );
  }
}

输出:

结论
名为“flexibleSpace”的属性就是您要查找的背景图像。

【讨论】:

    猜你喜欢
    • 2018-10-28
    • 2020-05-09
    • 2020-04-21
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 2015-06-20
    • 2011-02-28
    • 1970-01-01
    相关资源
    最近更新 更多