在 flutter 中使用动画 gif
Using an animated gif in flutter
我的资产文件夹中有一个 gif 动画。我想在我的应用程序登录页面上使用它,但如何使用?
我使用了这段代码:
Image.asset(
"login.gif",
height: 125.0,
width: 125.0,
),
但它什么也没做。
这是错误:
I/flutter (31581): The following assertion was thrown resolving an
image codec: I/flutter (31581): Unable to load asset: login.gif
删除 gif 路径中的前导 /。应该是assets/login.gif
此外,考虑使用更清洁的 Image.asset 构造函数,例如:
new Image.asset('assets/login.gif', width: 125.0, height: 125.0)
您必须提供来自 assets
的 gif
的 relative path
而不仅仅是文件名。
试试这个..
Image.asset('assets/login.gif', width: 15.0, height: 15.0)
还要确保您在 pubspec.yaml
中提到了它。
我的资产文件夹中有一个 gif 动画。我想在我的应用程序登录页面上使用它,但如何使用? 我使用了这段代码:
Image.asset(
"login.gif",
height: 125.0,
width: 125.0,
),
但它什么也没做。
这是错误:
I/flutter (31581): The following assertion was thrown resolving an image codec: I/flutter (31581): Unable to load asset: login.gif
删除 gif 路径中的前导 /。应该是assets/login.gif
此外,考虑使用更清洁的 Image.asset 构造函数,例如:
new Image.asset('assets/login.gif', width: 125.0, height: 125.0)
您必须提供来自 assets
的 gif
的 relative path
而不仅仅是文件名。
试试这个..
Image.asset('assets/login.gif', width: 15.0, height: 15.0)
还要确保您在 pubspec.yaml
中提到了它。