Untitled

 avatar
unknown
plain_text
2 months ago
1.7 kB
3
Indexable
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primaryColor: Colors.blue,
      ),
      home: const NameListScreen(),
    );
  }
}

class NameListScreen extends StatelessWidget {
  const NameListScreen({super.key});

  final List<Map<String, dynamic>> names = const [
    {'name': 'Ahmad Faisal Qodri', 'color': Colors.red},
    {'name': 'Ahmad Abdillah', 'color': Colors.green},
    {'name': 'Achmad Fadhillah', 'color': Colors.blue},
    {'name': 'Agus Setiawan', 'color': Colors.orange},
    {'name': 'Asyraf Mubarak', 'color': Colors.purple},
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Learn Basic Flutter'),
        backgroundColor: Colors.amber,
      ),
      body: ListView.builder(
        itemCount: names.length,
        itemBuilder: (context, index) {
          return Container(
            padding: const EdgeInsets.all(16.0),
            margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
            decoration: BoxDecoration(
              color: names[index]['color'],
              borderRadius: BorderRadius.circular(10),
            ),
            child: Text(
              names[index]['name'],
              style: const TextStyle(fontSize: 18, color: Colors.white),
              textAlign: TextAlign.center,
            ),
          );
        },
      ),
    );
  }
}
Editor is loading...
Leave a Comment