Hola tengo un proyecto flutter donde puedo hacer que las imagen me carguen de un Image.network. Este es mi main.dart.
class ShowCase extends StatelessWidget {
const ShowCase({
@required this.wideImage,
@required this.bookObject,
});
final String wideImage;
final Book bookObject;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => Details(bookObject)));
},
child: Row(
children: <Widget>[
Container(
height: 250,
width: 350,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.network(wideImage, fit: BoxFit.cover),
),
),
SizedBox(
width: 20,
)
],
),
);
}
}
class HotList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [Color(0xfff8f8f8), Colors.white],
),
border:
Border(bottom: BorderSide(color: Color(0xfff0f0f0), width: 2))),
padding: EdgeInsets.only(left: 20, right: 20, top: 35, bottom: 15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.only(bottom: 20.0),
child: Text(
"Locomotor",
style: TextStyle(
color: Colors.black,
fontSize: 30,
fontWeight: FontWeight.w600),
),
),
Container(
height: 320,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: booklist.books.length,
itemBuilder: (BuildContext context, int i) {
String title = booklist.books[i].title.length > 17
? booklist.books[i].title.substring(0, 15) + "..."
: booklist.books[i].title;
if (booklist.books[i].franchise) {
return Container();
} else {
return ShowBooks(
bookCoverImg: booklist.books[i].cover,
price: booklist.books[i].price,
author: booklist.books[i].author,
title: title,
bookObject: booklist.books[i],
);
}
},
),
)
],
),
);
}
}
Este es mi book.dart donde coloque el link de internet donde se aloja la imagen.
BookList booklist = BookList(books: [
Book(
title: "Planos anatómicos",
cover:
"https://upload.wikimedia.org/wikipedia/en/a/a9/Harry_Potter_and_the_Deathly_Hallows.jpg",
age: "ALL AGE",
author: "J. K. Rowling",
authorImg:
"https://images.gr-assets.com/authors/1510435123p5/1077326.jpg",
franchise: true,
genre: "Locomotor",
lanugage: "ENGLISH",
rating: 4.5,
price: 13.49,
summary:
"Without the guidance and protection of their professors, Harry (Daniel Radcliffe), Ron (Rupert Grint) and Hermione (Emma Watson) begin a mission to destroy the Horcruxes, the sources of Voldemort's immortality. Though they must rely on one another more than ever, dark forces threaten to tear them apart. Voldemort's Death Eaters have seized control of the Ministry of Magic and Hogwarts, and they are searching for Harry -- even as he and his friends prepare for the ultimate showdown.",
wideImage: "https://wallpaperplay.com/walls/full/9/a/9/64844.jpg"),
Book(
title: "A Song Of Ice And Fire",
cover:
"https://upload.wikimedia.org/wikipedia/en/thumb/d/dc/A_Song_of_Ice_and_Fire_book_collection_box_set_cover.jpg/220px-A_Song_of_Ice_and_Fire_book_collection_box_set_cover.jpg",
age: "ABOVE 18",
author: "George R. R. Martin",
authorImg:
"https://www.biography.com/.image/t_share/MTQ4NDc2MTkxNTY3NzgzMTE1/george_rr_martin_photo_mark_davis_wireimage_via_getty_images_164117282_resized.jpg",
franchise: true,
genre: "Sci-Fi",
lanugage: "ENGLISH",
price: 27.34,
rating: 4.4,
summary:
"Game of Thrones is roughly based on the storylines of A Song of Ice and Fire, set in the fictional Seven Kingdoms of Westeros and the continent of Essos. The series chronicles the violent dynastic struggles among the realm's noble families for the Iron Throne, while other families fight for independence from it.",
wideImage:
"https://images-na.ssl-images-amazon.com/images/I/91KwasehsHL._RI_.jpg"),
class Book {
String title;
double price;
String cover;
String author;
Book(
{@required this.title,
@required this.price,
});
}
Lo que quiera es que la imagen (por ejemplo la de "authoImage" me cargue desde la carpeta assets. osea quisiera que la imagen no se cargara desde internet, sino desde mi carpeta assets donde ya coloqué algunas imágenes. Como podria hacerlo? ya agregue la image asset en el pub spec.yaml ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... .....