Last active
May 6, 2020 18:06
-
-
Save remylavergne/b19b7995ebc5cdc57994b55bd5abb8bb to your computer and use it in GitHub Desktop.
[Flutter] ListView Builder example
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
import 'package:flutter/material.dart'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
final List<String> urls = [ | |
'https://youtube.com/video-super-fun', | |
'https://youtube.com/video-chat-qui-roule', | |
'https://youtube.com/snowboard', | |
'https://youtube.com/video-games', | |
'https://youtube.com/video-super-fun', | |
'https://youtube.com/video-chat-qui-roule', | |
'https://youtube.com/snowboard', | |
'https://youtube.com/video-games', | |
'https://youtube.com/video-super-fun', | |
'https://youtube.com/video-chat-qui-roule', | |
'https://youtube.com/snowboard', | |
'https://youtube.com/video-games', | |
'https://youtube.com/video-super-fun', | |
'https://youtube.com/video-chat-qui-roule', | |
'https://youtube.com/snowboard', | |
'https://youtube.com/video-games', | |
]; | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: ListView.builder( | |
itemCount: this.urls.length, | |
itemBuilder: (BuildContext context, int index) { | |
return MonItem(url: this.urls[index]); | |
}), | |
), | |
); | |
} | |
} | |
class MonItem extends StatelessWidget { | |
final String url; | |
MonItem({Key key, this.url}) : super(key: key); | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.green[200], | |
margin: EdgeInsets.all(16.0), | |
height: 100.0, | |
child: Center( | |
child: Text(this.url), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[Sample Live](URL : https://dartpad.dev/b19b7995ebc5cdc57994b55bd5abb8bb)