如何在 Flutter 中使用图像和其他视图作为背景

How to use images and other views as a backgrounds in Flutter

有什么可能的方式来设置我的背景:

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

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()),
      ),
    );
  }
}

如有任何建议,我们将不胜感激。

你得用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(),
  ],
),

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