Created
December 5, 2019 08:48
-
-
Save minikin/eb00c0e1c830d34442e697abe13c4fab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (c) 2019 Sasha Prokhorenko. | |
// Use of this source code is governed by a MIT license. | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
final List<String> _items = List<String>.generate( | |
100, (id) => 'https://picsum.photos/id/$id/500/500'); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('Flutter Demo'), | |
), | |
body: SafeArea( | |
child: Container( | |
margin: const EdgeInsets.all(8), | |
child: ListView.builder( | |
itemCount: _items.length, | |
itemBuilder: (_, index) { | |
return PhotoItem( | |
imageUrl: _items[index], | |
); | |
}, | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
class PhotoItem extends StatelessWidget { | |
final String imageUrl; | |
const PhotoItem({ | |
@required this.imageUrl, | |
Key key, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.grey[200], | |
margin: const EdgeInsets.all(4), | |
child: Image.network( | |
imageUrl, | |
fit: BoxFit.cover, | |
cacheWidth: 600, | |
cacheHeight: 600, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment