diff --git a/lib/database/database_helper.dart b/lib/database/database_helper.dart index 2e1b389..ab9076d 100644 --- a/lib/database/database_helper.dart +++ b/lib/database/database_helper.dart @@ -1,6 +1,7 @@ -import 'package:sqflite_common_ffi/sqflite_ffi.dart'; -import 'package:path/path.dart'; import '../models/contact.dart'; +import 'package:path/path.dart'; + +import 'package:sqflite_common_ffi/sqflite_ffi.dart'; class DatabaseHelper { static final DatabaseHelper _instance = DatabaseHelper._internal(); diff --git a/lib/main.dart b/lib/main.dart index f94fb7b..5878ff5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:sqflite_common_ffi/sqflite_ffi.dart'; +import 'package:contacts_dataist_ir/screens/contact_list_screen.dart'; void main() { + WidgetsFlutterBinding.ensureInitialized(); + sqfliteFfiInit(); + databaseFactory = databaseFactoryFfi; runApp(const MyApp()); } @@ -10,34 +15,12 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( - title: 'Flutter Demo', + title: 'Contacts Dataist IR', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), + useMaterial3: true, ), - home: const MyHomePage(title: ''), - ); - } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - - title: Text(widget.title), - ), - body: Center(child: Column()), + home: const ContactListScreen(), ); } } diff --git a/lib/screens/contact_list_screen.dart b/lib/screens/contact_list_screen.dart index 6e53b18..0b03173 100644 --- a/lib/screens/contact_list_screen.dart +++ b/lib/screens/contact_list_screen.dart @@ -1,5 +1,5 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/foundation.dart'; import 'package:contacts_dataist_ir/models/contact.dart'; import 'package:contacts_dataist_ir/database/database_helper.dart'; @@ -48,40 +48,49 @@ class _ContactListScreenState extends State { title: const Text('Contacts Dataist IR'), backgroundColor: Theme.of(context).colorScheme.primary, ), - body: _isLoading - ? const Center(child: CircularProgressIndicator()) - : _contacts.isEmpty - ? const Center( - child: Text('No contacts found. Add a new one!', style: TextStyle(fontSize: 18)), - ) - : ListView.builder( - itemCount: _contacts.length, - itemBuilder: (context, index) { - final contact = _contacts[index]; - return Card( - margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 5), - child: ListTile( - title: Text(contact.name), - subtitle: Text(contact.phone ?? contact.email ?? 'No phone or email'), - onTap: () { - if (kDebugMode) { - print('Tapped on ${contact.name}'); - } - }, - trailing: IconButton( - icon: const Icon(Icons.delete, color: Colors.red), - onPressed: () async { - if (kDebugMode) { - print('Delete ${contact.name}'); - } - await _dbHelper.deleteContact(contact.id!); - _loadContacts(); + body: + _isLoading + ? const Center(child: CircularProgressIndicator()) + : _contacts.isEmpty + ? const Center( + child: Text( + 'No contacts found. Add a new one!', + style: TextStyle(fontSize: 18), + ), + ) + : ListView.builder( + itemCount: _contacts.length, + itemBuilder: (context, index) { + final contact = _contacts[index]; + return Card( + margin: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 5, + ), + child: ListTile( + title: Text(contact.name), + subtitle: Text( + contact.phone ?? contact.email ?? 'No phone or email', + ), + onTap: () { + if (kDebugMode) { + print('Tapped on ${contact.name}'); + } + }, + trailing: IconButton( + icon: const Icon(Icons.delete, color: Colors.red), + onPressed: () async { + if (kDebugMode) { + print('Delete ${contact.name}'); + } + await _dbHelper.deleteContact(contact.id!); + _loadContacts(); + }, + ), + ), + ); }, ), - ), - ); - }, - ), floatingActionButton: FloatingActionButton( onPressed: () { if (kDebugMode) { @@ -92,4 +101,4 @@ class _ContactListScreenState extends State { ), ); } -} \ No newline at end of file +}