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 :
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',
),
];
but the image didn't show up, I've made another code like this ( file place_screen.dart ) :
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()
]));
}
}
in pubspec.yaml : ( I've already used tab button not space between "-" and "assets/.." )
uses-material-design: true
assets:
- assets/
- assets/icons/
- assets/frame.png
- assets/pvj.png
try close ide & clear cache in app and re run .