Show loading while image is loading in flutter

This Article is posted by seven.srikanth at 10/2/2021 11:48:25 AM



Here is an example of how to show loading while an image is loading in flutter. 
For this, you need to add your loading icon into pubspec.yaml file. 
And then use the FadeInImage widget.
Here is the full code from main.dart file. 

import 'package:flutter/material.dart';
main(List<String> args) {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@ override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(body: MyHomePage()),
);
}
}
class MyHomePage extends StatelessWidget {
@ override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.all(38.0),
child: FadeInImage(
image: NetworkImage(
'https://flutter.dev/assets/images/shared/brand/flutter/logo/flutter-lockup.png'),
placeholder: AssetImage('assets/spinner2.gif'),
),
),
);
}
}
Thanks,
Srikanth

Tags: How to show loading while image is loading;








0 Comments
Login to comment.
Recent Comments












© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com