Skip to content

Instantly share code, notes, and snippets.

@remylavergne
Last active May 6, 2020 18:06
Show Gist options
  • Save remylavergne/b19b7995ebc5cdc57994b55bd5abb8bb to your computer and use it in GitHub Desktop.
Save remylavergne/b19b7995ebc5cdc57994b55bd5abb8bb to your computer and use it in GitHub Desktop.
[Flutter] ListView Builder example
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),
),
);
}
}
@remylavergne
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment