2024-10-26 20:53:30 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-10-29 23:28:08 +00:00
|
|
|
import 'package:dialer/features/contacts/contact_page.dart';
|
|
|
|
import 'package:dialer/features/favorites/favorites_page.dart';
|
|
|
|
import 'package:dialer/features/history/history_page.dart';
|
|
|
|
import 'package:dialer/features/composition/composition.dart';
|
2024-10-31 15:15:00 +00:00
|
|
|
import 'package:flutter_contacts/flutter_contacts.dart';
|
2024-11-06 20:00:35 +00:00
|
|
|
import 'package:dialer/features/settings/settings.dart';
|
2024-10-26 20:53:30 +00:00
|
|
|
|
2024-10-29 23:28:08 +00:00
|
|
|
class _MyHomePageState extends State<MyHomePage>
|
|
|
|
with SingleTickerProviderStateMixin {
|
2024-10-26 20:53:30 +00:00
|
|
|
late TabController _tabController;
|
2024-10-31 15:15:00 +00:00
|
|
|
List<Contact> _allContacts = [];
|
|
|
|
List<Contact> _contactSuggestions = [];
|
2024-10-26 20:53:30 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-12-17 19:31:39 +00:00
|
|
|
// Set the TabController length to 3
|
|
|
|
_tabController = TabController(length: 3, vsync: this, initialIndex: 1);
|
2024-10-26 20:53:30 +00:00
|
|
|
_tabController.addListener(_handleTabIndex);
|
2024-10-31 15:15:00 +00:00
|
|
|
_fetchContacts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _fetchContacts() async {
|
|
|
|
if (await FlutterContacts.requestPermission()) {
|
|
|
|
_allContacts = await FlutterContacts.getContacts(withProperties: true);
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _onSearchChanged(String query) {
|
|
|
|
print("Search query: $query");
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
if (query.isEmpty) {
|
|
|
|
_contactSuggestions = List.from(_allContacts);
|
|
|
|
} else {
|
|
|
|
_contactSuggestions = _allContacts.where((contact) {
|
|
|
|
return contact.displayName
|
|
|
|
.toLowerCase()
|
|
|
|
.contains(query.toLowerCase());
|
|
|
|
}).toList();
|
|
|
|
}
|
|
|
|
});
|
2024-10-26 20:53:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
_tabController.removeListener(_handleTabIndex);
|
|
|
|
_tabController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _handleTabIndex() {
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
|
2024-10-29 23:28:08 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Colors.black,
|
|
|
|
body: Column(
|
|
|
|
children: [
|
2024-12-17 19:31:39 +00:00
|
|
|
// Search Bar and 3-dot menu
|
2024-10-29 23:28:08 +00:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
2024-10-31 15:15:00 +00:00
|
|
|
top: 24.0,
|
|
|
|
bottom: 10.0,
|
|
|
|
left: 16.0,
|
|
|
|
right: 16.0,
|
2024-10-26 20:53:30 +00:00
|
|
|
),
|
2024-12-17 19:31:39 +00:00
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: const Color.fromARGB(255, 30, 30, 30),
|
|
|
|
borderRadius: BorderRadius.circular(12.0),
|
|
|
|
border: Border(
|
|
|
|
top: BorderSide(color: Colors.grey.shade800, width: 1),
|
|
|
|
left: BorderSide(color: Colors.grey.shade800, width: 1),
|
|
|
|
right: BorderSide(color: Colors.grey.shade800, width: 1),
|
|
|
|
bottom:
|
|
|
|
BorderSide(color: Colors.grey.shade800, width: 2),
|
2024-10-29 23:28:08 +00:00
|
|
|
),
|
|
|
|
),
|
2024-12-17 19:31:39 +00:00
|
|
|
child: SearchAnchor(
|
|
|
|
builder:
|
|
|
|
(BuildContext context, SearchController controller) {
|
|
|
|
return SearchBar(
|
|
|
|
controller: controller,
|
|
|
|
padding:
|
|
|
|
MaterialStateProperty.all<EdgeInsetsGeometry>(
|
|
|
|
const EdgeInsets.only(
|
|
|
|
top: 6.0,
|
|
|
|
bottom: 6.0,
|
|
|
|
left: 16.0,
|
|
|
|
right: 16.0,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
controller.openView();
|
|
|
|
_onSearchChanged('');
|
|
|
|
},
|
|
|
|
backgroundColor: MaterialStateProperty.all(
|
|
|
|
const Color.fromARGB(255, 30, 30, 30)),
|
|
|
|
hintText: 'Search contacts',
|
|
|
|
hintStyle: MaterialStateProperty.all(
|
|
|
|
const TextStyle(color: Colors.grey, fontSize: 16.0),
|
|
|
|
),
|
|
|
|
leading: const Icon(
|
|
|
|
Icons.search,
|
|
|
|
color: Colors.grey,
|
|
|
|
size: 24.0,
|
|
|
|
),
|
|
|
|
shape:
|
|
|
|
MaterialStateProperty.all<RoundedRectangleBorder>(
|
|
|
|
RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(12.0),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
viewOnChanged: (query) {
|
|
|
|
_onSearchChanged(query);
|
|
|
|
},
|
|
|
|
suggestionsBuilder:
|
|
|
|
(BuildContext context, SearchController controller) {
|
|
|
|
return _contactSuggestions.map((contact) {
|
|
|
|
return ListTile(
|
|
|
|
key: ValueKey(contact.id),
|
|
|
|
title: Text(contact.displayName,
|
|
|
|
style: const TextStyle(color: Colors.white)),
|
|
|
|
onTap: () {
|
|
|
|
controller.closeView(contact.displayName);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}).toList();
|
|
|
|
},
|
2024-10-29 23:28:08 +00:00
|
|
|
),
|
2024-12-17 19:31:39 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
// 3-dot menu
|
|
|
|
PopupMenuButton<String>(
|
|
|
|
icon: const Icon(Icons.more_vert, color: Colors.white),
|
|
|
|
itemBuilder: (BuildContext context) => [
|
|
|
|
const PopupMenuItem<String>(
|
|
|
|
value: 'settings',
|
|
|
|
child: Text('Settings'),
|
2024-10-29 23:28:08 +00:00
|
|
|
),
|
2024-12-17 19:31:39 +00:00
|
|
|
],
|
|
|
|
onSelected: (String value) {
|
|
|
|
if (value == 'settings') {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => const SettingsPage()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2024-10-26 20:53:30 +00:00
|
|
|
),
|
|
|
|
),
|
2024-10-29 23:28:08 +00:00
|
|
|
// Main content with TabBarView
|
|
|
|
Expanded(
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
TabBarView(
|
|
|
|
controller: _tabController,
|
|
|
|
children: const [
|
|
|
|
FavoritePage(),
|
|
|
|
HistoryPage(),
|
|
|
|
ContactPage(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
right: 20,
|
|
|
|
bottom: 20,
|
|
|
|
child: FloatingActionButton(
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) => const CompositionPage(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
backgroundColor: Colors.blue,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(45),
|
|
|
|
),
|
|
|
|
child: const Icon(Icons.dialpad, color: Colors.white),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2024-10-26 20:53:30 +00:00
|
|
|
],
|
|
|
|
),
|
2024-10-29 23:28:08 +00:00
|
|
|
bottomNavigationBar: Container(
|
|
|
|
color: Colors.black,
|
|
|
|
child: TabBar(
|
|
|
|
controller: _tabController,
|
|
|
|
tabs: [
|
|
|
|
Tab(
|
|
|
|
icon: Icon(_tabController.index == 0
|
|
|
|
? Icons.star
|
|
|
|
: Icons.star_border)),
|
|
|
|
Tab(
|
|
|
|
icon: Icon(_tabController.index == 1
|
|
|
|
? Icons.access_time_filled
|
|
|
|
: Icons.access_time_outlined)),
|
|
|
|
Tab(
|
|
|
|
icon: Icon(_tabController.index == 2
|
|
|
|
? Icons.contacts
|
|
|
|
: Icons.contacts_outlined)),
|
|
|
|
],
|
|
|
|
labelColor: Colors.white,
|
|
|
|
unselectedLabelColor: const Color.fromARGB(255, 158, 158, 158),
|
|
|
|
indicatorSize: TabBarIndicatorSize.label,
|
|
|
|
indicatorColor: Colors.white,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-10-26 20:53:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
|
|
|
const MyHomePage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
_MyHomePageState createState() => _MyHomePageState();
|
|
|
|
}
|