All_Project: Refactored 💫
This commit is contained in:
parent
4b31ec316a
commit
f847a97d03
|
@ -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();
|
||||
|
|
|
@ -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<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()),
|
||||
home: const ContactListScreen(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,21 +48,30 @@ class _ContactListScreenState extends State<ContactListScreen> {
|
|||
title: const Text('Contacts Dataist IR'),
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
body: _isLoading
|
||||
body:
|
||||
_isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _contacts.isEmpty
|
||||
? 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(
|
||||
itemCount: _contacts.length,
|
||||
itemBuilder: (context, index) {
|
||||
final contact = _contacts[index];
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 5,
|
||||
),
|
||||
child: ListTile(
|
||||
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: () {
|
||||
if (kDebugMode) {
|
||||
print('Tapped on ${contact.name}');
|
||||
|
|
Loading…
Reference in New Issue