most recent 30 from stackoverflow.com
2026-05-01T14:44:34Z
https://stackoverflow.com/feeds/question/72400542
https://creativecommons.org/licenses/by-sa/4.0/rdf
https://stackoverflow.com/q/72400542
0
Jesselyn Firesta
https://stackoverflow.com/users/15434076
2022-05-27T04:42:41Z
2022-05-27T05:22:25Z
<p>I've made class model of places, and I want to show the logo of each place, I add the image location folder in class named place_model.dart and this is the code for place_model.dart :</p>
<pre><code>class Place{
final String imageUrl;
final String mall;
final String city;
Place({required this.imageUrl, required this.mall, required this.city});
}
final places = [
Place(
imageUrl : 'assets/pvj.png',
mall : 'Paris Van Java',
city:'Bandung',
),
Place(
imageUrl : '',
mall : 'Festival City Link',
city:'Bandung',
),
Place(
imageUrl : '',
mall : 'Istana Plaza',
city:'Bandung',
),
];
</code></pre>
<p>but the image didn't show up, I've made another code like this ( file place_screen.dart ) :</p>
<pre><code>import 'package:flutter/material.dart';
import 'package:smartparking/model/place_model.dart';
class PlaceScreen extends StatefulWidget{
@override
_PlaceScreenState createState() => _PlaceScreenState();
}
class _PlaceScreenState extends State<PlaceScreen>{
Column _buildMallPlaces(){
List<Widget> mallPlaces =[];
places.forEach((place){
mallPlaces.add(
Container(
height: 80.0,
child: Center(
child: ListTile(
leading: ConstrainedBox(
constraints: BoxConstraints(
minWidth: 20,
minHeight: 20,
maxWidth: 30,
maxHeight: 30,
),
child: Image(image: AssetImage(place.imageUrl)),
),
title: Text(
place.mall,
style: TextStyle(
fontSize: 18.0,
fontWeight : FontWeight.w600,
),
),
subtitle: Text(
'${place.city}',
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w600,
),
),
))));
});
return Column(children: mallPlaces);
}
@override
Widget build(BuildContext context){
return Scaffold(
body: ListView(
padding: EdgeInsets.symmetric(horizontal: 25, vertical: 50),
children:<Widget>[
SizedBox(height: 10.0),
Text('Select Mall',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),),
SizedBox(height: 20,),_buildMallPlaces()
]));
}
}
</code></pre>
<p>in pubspec.yaml : ( I've already used tab button not space between "-" and "assets/.." )</p>
<pre><code>uses-material-design: true
assets:
- assets/
- assets/icons/
- assets/frame.png
- assets/pvj.png
</code></pre>
https://stackoverflow.com/questions/72400542/-/72400591#72400591
0
DiyorbekDev
https://stackoverflow.com/users/15398171
2022-05-27T04:50:22Z
2022-05-27T04:50:22Z
<p>Rewrite assets and <code>flutter pub get</code></p>
<pre><code>flutter:
uses-material-design: true
assets:
- assets/icons/
fonts:
- family: Inter
fonts:
- asset: assets/fonts/Inter-Regular.ttf
</code></pre>
https://stackoverflow.com/questions/72400542/-/72400607#72400607
0
btm me
https://stackoverflow.com/users/14576258
2022-05-27T04:53:04Z
2022-05-27T04:53:04Z
<p>try close ide & clear cache in app and re run .</p>
https://stackoverflow.com/questions/72400542/-/72400619#72400619
0
Taz
https://stackoverflow.com/users/8912043
2022-05-27T04:54:29Z
2022-05-27T04:54:29Z
<p><code>uses-material-design</code> and <code>assets</code> must be the same depth.</p>
<pre><code>flutter:
uses-material-design: true
assets:
- assets/
</code></pre>
https://stackoverflow.com/questions/72400542/-/72400767#72400767
0
Rahul Pandey
https://stackoverflow.com/users/17615801
2022-05-27T05:18:18Z
2022-05-27T05:18:18Z
<p>Better don't define each and every image in the pubspec.yaml isntead just paste this it will work.
1)</p>
<pre><code>flutter:
uses-material-design: true
assets:
- assets/
</code></pre>
<ol start="2">
<li></li>
</ol>
<p>And make sure you have images in the assets folder and if this still doesn't work try to replace</p>
<pre><code>child: Image(image: AssetImage(place.imageUrl)),
</code></pre>
<p>with</p>
<pre><code>child: AssetImage("Imahe.png"),
</code></pre>
<ol start="3">
<li>Invalidate Cache and Restart and run the project !!</li>
</ol>
https://stackoverflow.com/questions/72400542/-/72400803#72400803
0
nesimtunc
https://stackoverflow.com/users/381807
2022-05-27T05:22:25Z
2022-05-27T05:22:25Z
<p>This way is working, the changes are based on Flutter 3.</p>
<ul>
<li>I have the put the image in <code>images</code> folder that I created in root folder.</li>
<li>I put condition if the place's imageUrl is empty or not.</li>
<li>Other language syntax and suggestions from Flutter.</li>
</ul>
<pre class="lang-dart prettyprint-override"><code>class PlaceScreen extends StatefulWidget {
@override
_PlaceScreenState createState() => _PlaceScreenState();
}
class _PlaceScreenState extends State<PlaceScreen> {
Column _buildMallPlaces() {
List<Widget> mallPlaces = [];
for (var place in places) {
mallPlaces.add(SizedBox(
height: 80.0,
child: Center(
child: ListTile(
leading: place.imageUrl.isEmpty
? null
: ConstrainedBox(
constraints: const BoxConstraints(
minWidth: 20,
minHeight: 20,
maxWidth: 30,
maxHeight: 30,
),
child: Image(image: AssetImage(place.imageUrl)),
),
title: Text(
place.mall,
style: const TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w600,
),
),
subtitle: Text(
place.city,
style: const TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w600,
),
),
))));
}
return Column(children: mallPlaces);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 50),
children: <Widget>[
const SizedBox(height: 10.0),
const Text(
'Select Mall',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 20,
),
_buildMallPlaces()
]));
}
}
</code></pre>
<p><a href="https://i.sstatic.net/4c3rYl.png?s=300" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4c3rYl.png?s=300" alt="enter image description here" /></a></p>