Untitled
unknown
dart
8 months ago
1.4 kB
5
Indexable
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key}); // ✅ Tambahkan "const"
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: Text('Nama Teman')),
body: NameListWidget(),
),
);
}
}
class NameListWidget extends StatelessWidget {
final List<Map<String, dynamic>> friends = [
{'name': 'Nauval', 'color': Colors.red},
{'name': 'Agus', 'color': Colors.green},
{'name': 'Ammar', 'color': Colors.purple},
{'name': 'Aslam', 'color': Colors.blue},
{'name': 'Faqih', 'color': Colors.orange},
];
@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: friends.length,
itemBuilder: (context, index) {
return Container(
margin: const EdgeInsets.all(8),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: friends[index]['color'],
borderRadius: BorderRadius.circular(10),
),
child: Text(
friends[index]['name'],
style: const TextStyle(fontSize: 18, color: Colors.white),
),
);
},
);
}
}Editor is loading...
Leave a Comment