flutter - 如何在颤动的容器背景中显示 Lottie 文件
问题描述
现在显示这样的 Lottie 文件。
Container(
width: 400,
child: Lottie.asset("assets/lotties/GamePlanAnimation.json")
);
现在我需要将 Lottie 文件显示为背景
解决方案
首先,我使用的解决方案创建了一个单独的类,您将图像设置为应用程序屏幕的背景
class BackgroundWidget extends StatelessWidget {
final childView;
BackgroundWidget({required this.childView});
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
image: DecorationImage(
alignment: Alignment.bottomCenter, //set as like you want
image: AssetImage(
'assets/background.png',
),
),
),
child: ClipRRect(
// make sure we apply clip it properly
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: Container(
alignment: Alignment.center,
color: Colors.white.withOpacity(0.8),
child: childView,
),
),
),
);
}
}
然后你可以像这样在任何地方使用这个小部件类。
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Color(0xff18728a),
),
home: Scaffold(
appBar: AppBar(
title: Text('Dashboard'),
brightness: Brightness.dark,
),
body: SafeArea(
child: BackgroundWidget(
// here is your widget class for background
childView: Container(),
),
),
),
);
推荐阅读
- ruby-on-rails - 生产中的 Rails 应用程序:无法加载 css 和 js 文件
- whmcs - 如何使用一些触发 URL 执行测试 WHMCS Hook?
- java - Docker 容器中的 Spring Boot 应用程序:无法打开 ServletContext 资源 [/WEB-INF/views/login.html]
- javascript - 选择框 全选/取消全选或选择一个选项 限制多个选项
- bash - 如何将参数从fastlane传递到shell文件
- python - 在 Excel 工作表中删除和替换 Pandas DataFrame
- spring-boot - 使用 keycloak 的安全微服务 Spring Boot 应用程序
- python - GridSearchCV - 应该使用哪些数据?
- json - 使用嵌套 JSON 作为数据 + BLoC 模式的 Flutter Post 请求
- python - 如果一个键具有一个或多个值,则 python 迭代字典值