diff options
Diffstat (limited to 'lib/main.dart')
| -rw-r--r-- | lib/main.dart | 89 |
1 files changed, 2 insertions, 87 deletions
diff --git a/lib/main.dart b/lib/main.dart index fd48c14..805ef69 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,92 +1,7 @@ -import 'dart:async'; - import 'package:flutter/material.dart'; +import 'ui.dart'; + void main() { runApp(const UI()); } - -class UI extends StatelessWidget { - const UI({super.key}); - - @override - Widget build(BuildContext context) { - return const MaterialApp( - home: ContactList(), - ); - } -} - -class Contact { - final String address; - bool isOpen; - - Contact({required this.address, required this.isOpen}); -} - -class ContactList extends StatefulWidget { - const ContactList({super.key}); - - @override - State<ContactList> createState() => _ContactListState(); -} - -class _ContactListState extends State<ContactList> { - late final List<Contact> contacts; - Timer? _timer; - - @override - void initState() { - super.initState(); - - contacts = <Contact>[ - Contact(address: "Living Room Window", isOpen: false), - Contact(address: "Front Door", isOpen: true), - Contact(address: "Back Door", isOpen: false), - Contact(address: "Garage Window", isOpen: true), - ]; - - _timer = Timer.periodic(const Duration(seconds: 1), (_) { - setState(() { - contacts[0].isOpen = !contacts[0].isOpen; - }); - }); - } - - @override - void dispose() { - _timer?.cancel(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: const Text("Contacts")), - body: ListView.builder( - itemCount: contacts.length, - itemBuilder: (BuildContext context, int index) { - final Contact contact = contacts[index]; - return ContactTile(contact: contact); - }, - ), - ); - } -} - -class ContactTile extends StatelessWidget { - final Contact contact; - - const ContactTile({super.key, required this.contact}); - - @override - Widget build(BuildContext context) { - return ListTile( - leading: Icon( - contact.isOpen ? Icons.meeting_room : Icons.door_front_door, - color: contact.isOpen ? Colors.red : Colors.green, - ), - title: Text(contact.address), - ); - } -} |
