【问题标题】:How to use images and other views as a backgrounds in Flutter如何在 Flutter 中使用图像和其他视图作为背景
【发布时间】:2020-11-22 15:28:08
【问题描述】:

像这样设置我的背景的可能方法是什么:

这个颜色是我在我的应用中使用的颜色

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        backgroundColor: Color(0xff00BCD1),
        appBar: AppBar(
          title: Text('Flutter Screen Background Color Example'),
        ),
        body: Center(child: Body()),
      ),
    );
  }
}

我们将不胜感激。

【问题讨论】:

  • 如果颜色代码正确,只需从屏幕上删除AppBar

标签: flutter dart flutter-layout background-color flutter-design


【解决方案1】:

你必须使用gradient

Container(
  height: double.infinity,
  width: double.infinity,
  decoration: BoxDecoration(
    gradient: LinearGradient(
      begin: Alignment.topLeft,
      end: Alignment.bottomRight,
      colors: [Color(0xff5a6c92), Color(0xff252b37)],
    ),
  ),
),

如果您不清楚这个答案,请查看此内容https://www.digitalocean.com/community/tutorials/flutter-flutter-gradient

如果您想将此用作背景,请使用 Stack 小部件来执行此操作

Stack(
  fit: StackFit.expand,
  children: [
    Container(
      height: double.infinity,
      width: double.infinity,
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
          colors: [Color(0xff5a6c92), Color(0xff252b37)],
        ),
      ),
    ),
    Otherwidgets(),
    Otherwidgets(),
    Otherwidgets(),
    Otherwidgets(),
  ],
),

阅读更多关于stackhttps://api.flutter.dev/flutter/widgets/Stack-class.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-10
    • 2012-04-26
    • 2021-09-01
    • 2019-08-19
    • 2020-06-02
    • 1970-01-01
    相关资源
    最近更新 更多