How to add an image to the Project?

This Article is posted by seven.srikanth at 8/27/2018 1:36:25 PM



<p>Follow the below steps to add images to the Flutter project. Create a Folder call images or with any other name and add images over there. And then you need to update in the pubspec.yaml file. WIthout adding the details to pubspec.yaml file, you cannot utilize those images.<br /> color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Consolas, "Courier New", monospace; line-height: 19px; white-space: pre-wrap;](color: rgb(86, 156, 214);](name: color: rgb(206, 145, 120);](flutterimagesexamplescolor: rgb(86, 156, 214);](description: color: rgb(206, 145, 120);](A new Flutter project. color: rgb(86, 156, 214);](dependencies: color: rgb(86, 156, 214);](flutter: color: rgb(86, 156, 214);](sdk: color: rgb(206, 145, 120);](flutter color: rgb(86, 156, 214);](cupertino_icons: color: rgb(206, 145, 120);](^0.1.2 color: rgb(86, 156, 214);](dev_dependencies: color: rgb(86, 156, 214);](flutter_test: color: rgb(86, 156, 214);](sdk: color: rgb(206, 145, 120);](flutter color: rgb(86, 156, 214);](flutter: color: rgb(86, 156, 214);](uses-material-design: color: rgb(86, 156, 214);](true color: rgb(86, 156, 214);](assets:- color: rgb(206, 145, 120);](images/carimg.jpeg</p> <p>and then in main.dart page add the below code color: rgb(212, 212, 212); background-color: rgb(30, 30, 30); font-family: Consolas, "Courier New", monospace; line-height: 19px; white-space: pre-wrap;](color: rgb(86, 156, 214);](import color: rgb(206, 145, 120);]('package:flutter/material.dart'; color: rgb(86, 156, 214);](void color: rgb(220, 220, 170);](main() => color: rgb(220, 220, 170);](runApp(color: rgb(197, 134, 192);](new color: rgb(78, 201, 176);](MyApp()); color: rgb(86, 156, 214);](class color: rgb(78, 201, 176);](MyApp color: rgb(86, 156, 214);](extends color: rgb(78, 201, 176);](StatelessWidget { color: rgb(86, 156, 214);](@override color: rgb(78, 201, 176);](Widget color: rgb(220, 220, 170);](build(color: rgb(78, 201, 176);](BuildContext context) { color: rgb(197, 134, 192);](return color: rgb(197, 134, 192);](new color: rgb(78, 201, 176);](MaterialApp(title: color: rgb(206, 145, 120);]('Flutter Demo',theme: color: rgb(197, 134, 192);](new color: rgb(78, 201, 176);](ThemeData(primarySwatch: color: rgb(78, 201, 176);](Colors.blue,),home: color: rgb(197, 134, 192);](new color: rgb(78, 201, 176);](MyHomePage(title: color: rgb(206, 145, 120);]('Flutter Image Examples'),);}} color: rgb(86, 156, 214);](class color: rgb(78, 201, 176);](MyHomePage color: rgb(86, 156, 214);](extends color: rgb(78, 201, 176);](StatefulWidget { color: rgb(78, 201, 176);](MyHomePage({color: rgb(78, 201, 176);](Key key, color: rgb(86, 156, 214);](this.title}) : color: rgb(86, 156, 214);](super(key: key);</p> <p>color: rgb(86, 156, 214);](final color: rgb(78, 201, 176);](String title; color: rgb(86, 156, 214);](@override color: rgb(78, 201, 176);](_MyHomePageState color: rgb(220, 220, 170);](createState() => color: rgb(197, 134, 192);](new color: rgb(78, 201, 176);](_MyHomePageState();} color: rgb(86, 156, 214);](class color: rgb(78, 201, 176);](_MyHomePageState color: rgb(86, 156, 214);](extends color: rgb(78, 201, 176);](State { color: rgb(86, 156, 214);](@override color: rgb(78, 201, 176);](Widget color: rgb(220, 220, 170);](build(color: rgb(78, 201, 176);](BuildContext context) { color: rgb(197, 134, 192);](return color: rgb(197, 134, 192);](new color: rgb(78, 201, 176);](Scaffold(appBar: color: rgb(197, 134, 192);](new color: rgb(78, 201, 176);](AppBar(title: color: rgb(197, 134, 192);](new color: rgb(78, 201, 176);](Text(widget.title),),body: color: rgb(197, 134, 192);](new color: rgb(78, 201, 176);](Center(child: color: rgb(197, 134, 192);](new color: rgb(78, 201, 176);](Column(mainAxisAlignment: color: rgb(78, 201, 176);](MainAxisAlignment.center,children: [ color: rgb(78, 201, 176);](Image.color: rgb(220, 220, 170);](asset(color: rgb(206, 145, 120);]('images/carimg.jpeg',width: color: rgb(181, 206, 168);](600.0,height: color: rgb(181, 206, 168);](240.0,fit: color: rgb(78, 201, 176);](BoxFit.cover,)],),),);}}</p> <p>Thanks,Srikanth</p>


Tags: Add images to Flutter Project;








0 Comments
Login to comment.
Recent Comments