All_Project: Refactored 💫

This commit is contained in:
Hadi Mottale 2025-06-11 11:37:51 +03:30
parent 4b31ec316a
commit f847a97d03
3 changed files with 54 additions and 61 deletions

View File

@ -1,6 +1,7 @@
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import 'package:path/path.dart';
import '../models/contact.dart'; import '../models/contact.dart';
import 'package:path/path.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
class DatabaseHelper { class DatabaseHelper {
static final DatabaseHelper _instance = DatabaseHelper._internal(); static final DatabaseHelper _instance = DatabaseHelper._internal();

View File

@ -1,6 +1,11 @@
import 'package:flutter/material.dart'; 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() { void main() {
WidgetsFlutterBinding.ensureInitialized();
sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;
runApp(const MyApp()); runApp(const MyApp());
} }
@ -10,34 +15,12 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'Flutter Demo', title: 'Contacts Dataist IR',
theme: ThemeData( theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
), ),
home: const MyHomePage(title: ''), home: const ContactListScreen(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(child: Column()),
); );
} }
} }

View File

@ -1,5 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:contacts_dataist_ir/models/contact.dart'; import 'package:contacts_dataist_ir/models/contact.dart';
import 'package:contacts_dataist_ir/database/database_helper.dart'; import 'package:contacts_dataist_ir/database/database_helper.dart';
@ -48,21 +48,30 @@ class _ContactListScreenState extends State<ContactListScreen> {
title: const Text('Contacts Dataist IR'), title: const Text('Contacts Dataist IR'),
backgroundColor: Theme.of(context).colorScheme.primary, backgroundColor: Theme.of(context).colorScheme.primary,
), ),
body: _isLoading body:
_isLoading
? const Center(child: CircularProgressIndicator()) ? const Center(child: CircularProgressIndicator())
: _contacts.isEmpty : _contacts.isEmpty
? const Center( ? const Center(
child: Text('No contacts found. Add a new one!', style: TextStyle(fontSize: 18)), child: Text(
'No contacts found. Add a new one!',
style: TextStyle(fontSize: 18),
),
) )
: ListView.builder( : ListView.builder(
itemCount: _contacts.length, itemCount: _contacts.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final contact = _contacts[index]; final contact = _contacts[index];
return Card( return Card(
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 5), margin: const EdgeInsets.symmetric(
horizontal: 10,
vertical: 5,
),
child: ListTile( child: ListTile(
title: Text(contact.name), title: Text(contact.name),
subtitle: Text(contact.phone ?? contact.email ?? 'No phone or email'), subtitle: Text(
contact.phone ?? contact.email ?? 'No phone or email',
),
onTap: () { onTap: () {
if (kDebugMode) { if (kDebugMode) {
print('Tapped on ${contact.name}'); print('Tapped on ${contact.name}');