Created
November 4, 2022 15:18
-
-
Save leighajarett/66e6728e204021e3b9e0190be50d014b to your computer and use it in GitHub Desktop.
Flutter List Example
This file contains hidden or 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'; | |
import 'package:flutter/cupertino.dart'; | |
void main() { | |
runApp( | |
const App(), | |
); | |
} | |
class App extends StatelessWidget { | |
const App({ | |
Key? key, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return CupertinoApp( | |
home: const HomePage(), | |
); | |
} | |
} | |
class Person { | |
String name; | |
Person(this.name); | |
} | |
var items = [ | |
Person('Person 1'), | |
Person('Person 2'), | |
Person('Person 3'), | |
]; | |
class HomePage extends StatelessWidget { | |
const HomePage({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: ListView.builder( | |
itemCount: items.length, | |
itemBuilder: (context, index) { | |
return ListTile( | |
title: Text(items[index].name), | |
); | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment