Step 1: Init Flutter Project
First you need to create a new flutter project using "flutter create" command.
flutter create myapp
Step 2: Open project in VS Code or Android Studio
Next you have to open it on your text editor VS Code or Android Studio and run the sample app
Step 3: Open main.dart and Update Code
Crate a new StatelessWidget component and in this case I will be calling it "PostSrc". Inside it implement the "build" method that return StatelessWidget and Scaffold. Once you have that you can define the Image widget and have it wrapped with Center widget to place it on the centre of the screen.
void main() { runApp(PostSrc()); } class PostSrc extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar( title: const Text("PostSrc"), backgroundColor: Colors.green.shade300, ), backgroundColor: Colors.green.shade100, body: const Center( child: Image( image: NetworkImage('https://postsrc.com/img/attr.png'), width: 300, ), ), ), ); } }
- NetworkImage
- AssetImage
Leave a reply