动图录制所以图片有闪动,实际效果正常。
1.首先需要在目录在创建assets文件夹,用于存放资源文件。(loading.gif)
2.修改pubspec.yaml
assets:
- assets/loading.gif
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: FadeInImage.assetNetwork(
placeholder: "assets/loading.gif",
image: "https://tukuimg.bdstatic.com/scrop/6be65a47b2bc49e492385b8ebc486d14.gif"),
),
);
}
}
网友评论