Files
2026-05-26 18:01:57 +05:30

380 lines
14 KiB
Dart

// import 'package:flutter/material.dart';
// import 'package:flutter_contacts/flutter_contacts.dart';
// import 'package:nearledaily/constants/color_constants.dart';
// import 'package:permission_handler/permission_handler.dart'
// as permission_handler;
// import 'package:url_launcher/url_launcher.dart';
// import 'package:flutter/services.dart';
//
// import '../../constants/font_constants.dart';
// import '../../widgets/text_widget.dart';
//
// class ShowContactsScreen extends StatefulWidget {
// const ShowContactsScreen({super.key});
//
// @override
// State<ShowContactsScreen> createState() => _ShowContactsScreenState();
// }
//
// class _ShowContactsScreenState extends State<ShowContactsScreen>
// with WidgetsBindingObserver {
// List<Contact> _contacts = [];
// bool _loading = false;
// bool _permissionDenied = false;
//
// /// 🔹 ADDED
// bool _showDisclaimer = true;
//
// @override
// void initState() {
// super.initState();
// WidgetsBinding.instance.addObserver(this);
// _loadContacts();
// }
//
// @override
// void dispose() {
// WidgetsBinding.instance.removeObserver(this);
// super.dispose();
// }
//
// Future<void> _loadContacts() async {
// setState(() {
// _loading = true;
// _permissionDenied = false;
// });
//
// final bool granted = await FlutterContacts.requestPermission();
//
// if (!granted) {
// setState(() {
// _loading = false;
// _permissionDenied = true;
// });
// return;
// }
//
// try {
// final List<Contact> contacts = await FlutterContacts.getContacts(
// withProperties: true,
// withPhoto: true,
// );
//
// setState(() {
// _contacts = contacts
// .where((c) => c.phones.isNotEmpty)
// .toList()
// ..sort((a, b) => a.displayName.compareTo(b.displayName));
// _loading = false;
// });
// } catch (e) {
// setState(() {
// _loading = false;
// });
// ScaffoldMessenger.of(context).showSnackBar(
// SnackBar(
// content: ReusableTextWidget(
// text: "Error loading contacts: $e",
// fontSize: 14,
// fontWeight: FontWeight.w400,
// fontFamily: FontConstants.fontFamily,
// color: Colors.white,
// ),
// ),
// );
// }
// }
//
// Widget _buildAvatar(Contact contact) {
// if (contact.photo != null && contact.photo!.isNotEmpty) {
// return CircleAvatar(
// backgroundImage: MemoryImage(contact.photo!),
// );
// } else {
// String initials = "";
// final names = contact.displayName.split(" ");
// if (names.isNotEmpty) initials += names[0][0];
// if (names.length > 1) initials += names[1][0];
// return CircleAvatar(
// backgroundColor: Colors.primaries[
// contact.displayName.hashCode % Colors.primaries.length],
// child: ReusableTextWidget(
// text: initials.toUpperCase(),
// fontSize: 16,
// fontWeight: FontWeight.bold,
// fontFamily: FontConstants.fontFamily,
// color: Colors.white,
// ),
// );
// }
// }
//
// Future<void> _openWhatsApp(Contact contact) async {
// if (contact.phones.isEmpty) return;
//
// String phoneNumber =
// contact.phones.first.number.replaceAll(RegExp(r'\D'), '');
// final Uri url = Uri.parse("https://wa.me/$phoneNumber");
//
// if (await canLaunchUrl(url)) {
// await launchUrl(url, mode: LaunchMode.externalApplication);
// } else {
// ScaffoldMessenger.of(context).showSnackBar(
// const SnackBar(
// content: ReusableTextWidget(
// text: "Could not open WhatsApp",
// fontSize: 14,
// fontWeight: FontWeight.w400,
// fontFamily: FontConstants.fontFamily,
// color: Colors.white,
// ),
// ),
// );
// }
// }
//
// Future<void> _inviteWhatsApp(Contact contact) async {
// if (contact.phones.isEmpty) return;
//
// String phoneNumber =
// contact.phones.first.number.replaceAll(RegExp(r'\D'), '');
//
// final String message = Uri.encodeComponent(
// "Hey! Join me on Nearle Daily 🚀");
//
// final Uri url = Uri.parse("https://wa.me/$phoneNumber?text=$message");
//
// if (await canLaunchUrl(url)) {
// await launchUrl(url, mode: LaunchMode.externalApplication);
// } else {
// ScaffoldMessenger.of(context).showSnackBar(
// const SnackBar(
// content: ReusableTextWidget(
// text: "Could not open WhatsApp",
// fontSize: 14,
// fontWeight: FontWeight.w400,
// fontFamily: FontConstants.fontFamily,
// color: Colors.white,
// ),
// ),
// );
// }
// }
//
// @override
// Widget build(BuildContext context) {
// return AnnotatedRegion<SystemUiOverlayStyle>(
// value: const SystemUiOverlayStyle(
// statusBarColor: Colors.white, // White background
// statusBarIconBrightness: Brightness.dark, // Dark icons
// statusBarBrightness: Brightness.light, // iOS
// ),
// child: Scaffold(
// backgroundColor: Colors.white,
// appBar: AppBar(
// backgroundColor: Colors.white,
// surfaceTintColor: Colors.transparent,
// scrolledUnderElevation: 0,
// titleSpacing: -5,
// animateColor: false,
// elevation: 0,
// title: ReusableTextWidget(
// text: "Refer a friend",
// fontSize: 20,
// fontWeight: FontWeight.w600,
// fontFamily: FontConstants.fontFamily,
// color: Colors.black,
// ),
// iconTheme: const IconThemeData(color: Colors.black),
// ),
// body: Padding(
// padding: const EdgeInsets.only(left: 12.0, right: 12, bottom: 12),
// child: Column(
// children: [
// /// 🔹 MODIFIED DISCLAIMER ONLY
// if (_showDisclaimer)
// Stack(
// children: [
// Padding(
// padding: const EdgeInsets.only(top: 12.0),
// child: Container(
// width: double.infinity,
// padding: const EdgeInsets.all(14),
// margin: const EdgeInsets.only(bottom: 16),
// decoration: BoxDecoration(
// color: ColorConstants.primaryColor.withOpacity(0.08),
// borderRadius: BorderRadius.circular(12),
// ),
// child: const ReusableTextWidget(
// text:
// "We access contacts only to let you share\nor recommend to friends. Nothing is stored.",
// fontSize: 13,
// fontWeight: FontWeight.w500,
// fontFamily: FontConstants.fontFamily,
// color: Colors.black87,
// ),
// ),
// ),
// Positioned(
// top: 6,
// right: -3,
// child: IconButton(
// icon: const Icon(Icons.close, size: 18),
// onPressed: () {
// setState(() {
// _showDisclaimer = false;
// });
// },
// ),
// ),
// ],
// ),
//
// if (_loading)
// const Expanded(
// child: Center(child: CircularProgressIndicator()),
// ),
//
// if (_permissionDenied)
// Expanded(
// child: Center(
// child: Container(
// margin: const EdgeInsets.symmetric(horizontal: 24),
// padding: const EdgeInsets.all(24),
// decoration: BoxDecoration(
// color: Colors.red.withOpacity(0.05),
// borderRadius: BorderRadius.circular(20),
// border: Border.all(
// color: Colors.red.withOpacity(0.2),
// ),
// ),
// child: Column(
// mainAxisSize: MainAxisSize.min,
// children: [
// Container(
// padding: const EdgeInsets.all(18),
// decoration: BoxDecoration(
// color: Colors.red.withOpacity(0.12),
// shape: BoxShape.circle,
// ),
// child: const Icon(
// Icons.info_outline,
// color: Colors.red,
// size: 48,
// ),
// ),
// const SizedBox(height: 20),
// const ReusableTextWidget(
// text: "Contacts Access Needed",
// fontSize: 18,
// fontWeight: FontWeight.w600,
// fontFamily: FontConstants.fontFamily,
// color: Colors.black,
// ),
// const SizedBox(height: 8),
// const ReusableTextWidget(
// text:
// "Allow contacts permission to view\nand invite your friends easily.",
// fontSize: 14,
// fontWeight: FontWeight.w400,
// fontFamily: FontConstants.fontFamily,
// color: Colors.black54,
// textAlign: TextAlign.center,
// ),
// const SizedBox(height: 24),
// SizedBox(
// width: double.infinity,
// child: ElevatedButton(
// onPressed: permission_handler.openAppSettings,
// style: ElevatedButton.styleFrom(
// backgroundColor: Colors.red,
// elevation: 0,
// padding: const EdgeInsets.symmetric(vertical: 14),
// shape: RoundedRectangleBorder(
// borderRadius: BorderRadius.circular(12),
// ),
// ),
// child: const ReusableTextWidget(
// text: "Open Settings",
// fontSize: 15,
// fontWeight: FontWeight.w600,
// fontFamily: FontConstants.fontFamily,
// color: Colors.white,
// ),
// ),
// ),
// ],
// ),
// ),
// ),
// ),
//
// if (_contacts.isNotEmpty && !_loading && !_permissionDenied)
// Expanded(
// child: RefreshIndicator(
// onRefresh: _loadContacts,
// child: ListView.builder(
// itemCount: _contacts.length,
// itemBuilder: (context, index) {
// final contact = _contacts[index];
// final phones =
// contact.phones.map((p) => p.number).toList();
// final subtitle = phones.length > 1
// ? phones.sublist(0, 2).join(", ")
// : phones.first;
//
// return ListTile(
// leading: _buildAvatar(contact),
// title: ReusableTextWidget(
// text: contact.displayName.isEmpty
// ? "No Name"
// : contact.displayName,
// fontSize: 14,
// fontWeight: FontWeight.w600,
// fontFamily: FontConstants.fontFamily,
// color: Colors.black,
// ),
// subtitle: ReusableTextWidget(
// text: subtitle,
// fontSize: 13,
// fontWeight: FontWeight.w400,
// fontFamily: FontConstants.fontFamily,
// color: Colors.grey,
// ),
// trailing: TextButton(
// onPressed: () => _inviteWhatsApp(contact),
// child: const ReusableTextWidget(
// text: "Invite",
// fontSize: 14,
// fontWeight: FontWeight.bold,
// fontFamily: FontConstants.fontFamily,
// color: Colors.green,
// ),
// ),
// onTap: () => _openWhatsApp(contact),
// );
// },
// ),
// ),
// ),
//
// if (_contacts.isEmpty && !_loading && !_permissionDenied)
// const Expanded(
// child: Center(
// child: ReusableTextWidget(
// text: "No contacts found with phone numbers",
// fontSize: 16,
// fontWeight: FontWeight.w400,
// fontFamily: FontConstants.fontFamily,
// color: Colors.grey,
// ),
// ),
// ),
// ],
// ),
// ),
// ),
// );
// }
// }