整个屏幕的颤动渐变背景问题

问题描述 投票:0回答:1

我试图一次向所有屏幕添加渐变背景,所以我找到了一个好方法,但它没有按预期工作!!

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
        gradient: LinearGradient(
          colors: [
            Colors.red,
            Colors.white,
          ],
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
      ),
      child: MaterialApp(
        builder: EasyLoading.init(),
        home: Scaffold(
          backgroundColor: Colors.transparent,
        ),
      ),
    );
  }
}

检查代码后,我发现如果删除

builder: EasyLoading.init(),
,它就可以正常工作! 但我想要 EasyLoading ..那么有办法吗?

flutter background gradient builder
1个回答
0
投票

请尝试使用

Stack
小部件将渐变背景和 EasyLoading 相互叠加。

Stack(
      children: [
        Container(
          decoration: const BoxDecoration(
            gradient: LinearGradient(
              colors: [
                Colors.red,
                Colors.white,
              ],
              begin: Alignment.topLeft,
              end: Alignment.bottomRight,
            ),
          ),
        ),
        MaterialApp(
          builder: (context, child) {
            return Stack(
              children: [child!, EasyLoading.init()],
            );
          },
          home: Scaffold(
            backgroundColor: Colors.transparent,
          ),
        ),
      ],
    )

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.