1

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

这个应用程序

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

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

任何建议将被认真考虑。

4

1 回答 1

2

你必须使用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

于 2020-08-02T10:01:28.300 回答