first commit
This commit is contained in:
1837
lib/view/dashboard_view/dashboard_view.dart
Normal file
1837
lib/view/dashboard_view/dashboard_view.dart
Normal file
File diff suppressed because it is too large
Load Diff
611
lib/view/dashboard_view/searchScreen.dart
Normal file
611
lib/view/dashboard_view/searchScreen.dart
Normal file
@@ -0,0 +1,611 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:nearledaily/constants/color_constants.dart';
|
||||
|
||||
import '../../constants/font_constants.dart';
|
||||
import '../../controllers/tenant_controller /tenant_list.dart';
|
||||
import '../../widgets/text_widget.dart';
|
||||
import '../product/tenant_products.dart';
|
||||
|
||||
// ─── Search result modules ─────────────────────────────────────────────────────
|
||||
|
||||
class _SearchResult {
|
||||
final String tenantName;
|
||||
final String productName;
|
||||
final String subCatName;
|
||||
|
||||
const _SearchResult({
|
||||
required this.tenantName,
|
||||
required this.productName,
|
||||
required this.subCatName,
|
||||
});
|
||||
|
||||
factory _SearchResult.fromJson(Map<String, dynamic> json) => _SearchResult(
|
||||
tenantName: json['tenantname'] ?? '',
|
||||
productName: json['productname'] ?? '',
|
||||
subCatName: json['subcatname'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Screen ──────────────────────────────────────────────────────────────────
|
||||
|
||||
class SearchScreen extends StatefulWidget {
|
||||
const SearchScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<SearchScreen> createState() => _SearchScreenState();
|
||||
}
|
||||
|
||||
class _SearchScreenState extends State<SearchScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
final TenantController tenantController = Get.find();
|
||||
|
||||
late AnimationController _animationController;
|
||||
late Animation<double> _fadeAnimation;
|
||||
late Animation<Offset> _slideAnimation;
|
||||
|
||||
Timer? _debounce;
|
||||
bool _isSearching = false;
|
||||
List<_SearchResult> _searchResults = [];
|
||||
String _lastQuery = '';
|
||||
|
||||
static const String _searchBaseUrl =
|
||||
'https://fiesta.nearle.app/live/api/v1/mob/tenants/searchbykeyword';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_animationController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 400),
|
||||
);
|
||||
|
||||
_fadeAnimation = CurvedAnimation(
|
||||
parent: _animationController,
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
|
||||
_slideAnimation = Tween<Offset>(
|
||||
begin: const Offset(0, 0.05),
|
||||
end: Offset.zero,
|
||||
).animate(CurvedAnimation(
|
||||
parent: _animationController,
|
||||
curve: Curves.easeOut,
|
||||
));
|
||||
|
||||
_animationController.forward();
|
||||
_focusNode.addListener(() => setState(() {}));
|
||||
_searchController.addListener(_onSearchChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_debounce?.cancel();
|
||||
_animationController.dispose();
|
||||
_searchController.removeListener(_onSearchChanged);
|
||||
_searchController.dispose();
|
||||
_focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onSearchChanged() {
|
||||
final query = _searchController.text.trim();
|
||||
setState(() {});
|
||||
|
||||
if (query == _lastQuery) return;
|
||||
_lastQuery = query;
|
||||
_debounce?.cancel();
|
||||
|
||||
if (query.isEmpty) {
|
||||
setState(() {
|
||||
_searchResults = [];
|
||||
_isSearching = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
_debounce = Timer(const Duration(milliseconds: 400), () {
|
||||
_fetchSearchResults(query);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _fetchSearchResults(String keyword) async {
|
||||
if (!mounted) return;
|
||||
setState(() => _isSearching = true);
|
||||
|
||||
try {
|
||||
final uri = Uri.parse(
|
||||
'$_searchBaseUrl?keyword=${Uri.encodeComponent(keyword)}');
|
||||
final response =
|
||||
await http.get(uri).timeout(const Duration(seconds: 10));
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body) as Map<String, dynamic>;
|
||||
if (data['status'] == true && data['details'] is List) {
|
||||
final results = (data['details'] as List)
|
||||
.map((e) => _SearchResult.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
setState(() {
|
||||
_searchResults = results;
|
||||
_isSearching = false;
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
setState(() {
|
||||
_searchResults = [];
|
||||
_isSearching = false;
|
||||
});
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_searchResults = [];
|
||||
_isSearching = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
List<dynamic> get _filteredTenants {
|
||||
final query = _searchController.text.trim();
|
||||
if (query.isEmpty) return tenantController.searchtenants;
|
||||
|
||||
final matchedNames =
|
||||
_searchResults.map((r) => r.tenantName.toLowerCase()).toSet();
|
||||
|
||||
return tenantController.searchtenants
|
||||
.where(
|
||||
(t) => matchedNames.contains((t.tenantname ?? '').toLowerCase()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Widget _imagePlaceholder() {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Colors.grey.shade100, Colors.grey.shade400],
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Icon(Icons.store_outlined,
|
||||
size: 48, color: Colors.grey.shade400),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _navigateTo(dynamic item) {
|
||||
HapticFeedback.lightImpact();
|
||||
Get.to(
|
||||
() => ProductsScreen(
|
||||
tenantId: item.tenantid!,
|
||||
locationId: item.locationid!,
|
||||
categoryId: item.categoryid!,
|
||||
tenantName: item.tenantname!,
|
||||
locationname: item.locationname!,
|
||||
tenantLocation: item.suburb!,
|
||||
tenantImage: item.tenantimage!,
|
||||
tenantloc: item.locationid!,
|
||||
subCategoryName: "",
|
||||
),
|
||||
transition: Transition.cupertino,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: const Color(0xFFF6F6F6),
|
||||
body: Column(
|
||||
children: [
|
||||
// ── Search bar ────────────────────────────────────────────────
|
||||
SafeArea(
|
||||
bottom: false,
|
||||
child: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 12),
|
||||
child: Hero(
|
||||
tag: 'search_bar',
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: Container(
|
||||
height: 52,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: _focusNode.hasFocus
|
||||
? ColorConstants.primaryColor
|
||||
: Colors.grey.shade300,
|
||||
width: _focusNode.hasFocus ? 2 : 1,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _focusNode.hasFocus
|
||||
? ColorConstants.primaryColor.withOpacity(0.15)
|
||||
: Colors.black.withOpacity(0.06),
|
||||
blurRadius: _focusNode.hasFocus ? 12 : 8,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
focusNode: _focusNode,
|
||||
autofocus: true,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search stores or products...',
|
||||
hintStyle: TextStyle(
|
||||
color: Colors.grey.shade400,
|
||||
fontWeight: FontWeight.normal,
|
||||
),
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_isSearching)
|
||||
SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: ColorConstants.primaryColor,
|
||||
),
|
||||
)
|
||||
else if (_searchController.text.isNotEmpty)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear, size: 20),
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
setState(() {
|
||||
_searchResults = [];
|
||||
_lastQuery = '';
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// ── List ──────────────────────────────────────────────────────
|
||||
Expanded(
|
||||
child: Obx(() {
|
||||
if (tenantController.isLoading.value) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(
|
||||
color: ColorConstants.primaryColor),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Loading stores...',
|
||||
style: TextStyle(
|
||||
color: Colors.grey.shade600, fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final displayTenants = _filteredTenants;
|
||||
final hasQuery = _searchController.text.trim().isNotEmpty;
|
||||
|
||||
if (displayTenants.isEmpty) {
|
||||
return FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.search_off_rounded,
|
||||
size: 80, color: Colors.grey.shade300),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
hasQuery
|
||||
? 'No matching stores found'
|
||||
: 'No stores found',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Try searching with different keywords',
|
||||
style: TextStyle(
|
||||
fontSize: 14, color: Colors.grey.shade500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 30),
|
||||
physics: const BouncingScrollPhysics(),
|
||||
itemCount: displayTenants.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = displayTenants[index];
|
||||
|
||||
return FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: SlideTransition(
|
||||
position: _slideAnimation,
|
||||
child: _StoreListItem(
|
||||
item: item,
|
||||
index: index,
|
||||
imagePlaceholder: _imagePlaceholder(),
|
||||
onTap: () => _navigateTo(item),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── List item: banner image on top (outside card), info card below ──────────
|
||||
|
||||
class _StoreListItem extends StatelessWidget {
|
||||
final dynamic item;
|
||||
final int index;
|
||||
final Widget imagePlaceholder;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _StoreListItem({
|
||||
required this.item,
|
||||
required this.index,
|
||||
required this.imagePlaceholder,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final hasBanner = item.tenantbanner != null &&
|
||||
(item.tenantbanner as String).isNotEmpty;
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// ── Banner — tappable, rounded top corners, NO card background ─
|
||||
GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Hero(
|
||||
tag: 'store_${item.tenantid}_$index',
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(16),
|
||||
topRight: Radius.circular(16),
|
||||
),
|
||||
child: Container(
|
||||
height: 180,
|
||||
width: double.infinity,
|
||||
color: Colors.grey.shade200,
|
||||
child: hasBanner
|
||||
? Image.network(
|
||||
item.tenantbanner as String,
|
||||
fit: BoxFit.cover,
|
||||
loadingBuilder: (ctx, child, progress) =>
|
||||
progress == null ? child : _ShimmerLoading(),
|
||||
errorBuilder: (ctx, _, __) => imagePlaceholder,
|
||||
)
|
||||
: imagePlaceholder,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// ── Info card — flush below the image ───────────────────────
|
||||
_StoreInfoCard(item: item, onTap: onTap),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Info card: name + location only ─────────────────────────────────────────
|
||||
|
||||
class _StoreInfoCard extends StatefulWidget {
|
||||
final dynamic item;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _StoreInfoCard({required this.item, required this.onTap});
|
||||
|
||||
@override
|
||||
State<_StoreInfoCard> createState() => _StoreInfoCardState();
|
||||
}
|
||||
|
||||
class _StoreInfoCardState extends State<_StoreInfoCard>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _scaleController;
|
||||
late Animation<double> _scaleAnimation;
|
||||
bool _isPressed = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_scaleController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 150),
|
||||
);
|
||||
_scaleAnimation = Tween<double>(begin: 1.0, end: 0.98).animate(
|
||||
CurvedAnimation(parent: _scaleController, curve: Curves.easeInOut),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scaleController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTapDown: (_) {
|
||||
setState(() => _isPressed = true);
|
||||
_scaleController.forward();
|
||||
},
|
||||
onTapUp: (_) {
|
||||
setState(() => _isPressed = false);
|
||||
_scaleController.reverse();
|
||||
widget.onTap();
|
||||
},
|
||||
onTapCancel: () {
|
||||
setState(() => _isPressed = false);
|
||||
_scaleController.reverse();
|
||||
},
|
||||
child: ScaleTransition(
|
||||
scale: _scaleAnimation,
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 150),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(16),
|
||||
bottomRight: Radius.circular(16),
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _isPressed
|
||||
? Colors.black.withOpacity(0.04)
|
||||
: Colors.black.withOpacity(0.08),
|
||||
blurRadius: _isPressed ? 3 : 6,
|
||||
offset: Offset(0, _isPressed ? 1 : 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Store name
|
||||
ReusableTextWidget(
|
||||
text: widget.item.tenantname ?? '',
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
// Location
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.location_on_outlined,
|
||||
size: 13, color: Colors.grey.shade500),
|
||||
const SizedBox(width: 3),
|
||||
Expanded(
|
||||
child: ReusableTextWidget(
|
||||
text: widget.item.locationname ?? '',
|
||||
fontSize: 12,
|
||||
color: Colors.black54,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(Icons.arrow_forward_ios_rounded,
|
||||
size: 14, color: Colors.grey.shade400),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── Shimmer loading ──────────────────────────────────────────────────────────
|
||||
|
||||
class _ShimmerLoading extends StatefulWidget {
|
||||
@override
|
||||
State<_ShimmerLoading> createState() => _ShimmerLoadingState();
|
||||
}
|
||||
|
||||
class _ShimmerLoadingState extends State<_ShimmerLoading>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _ctrl;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_ctrl = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 1500),
|
||||
)..repeat();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ctrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _ctrl,
|
||||
builder: (_, __) => Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
Colors.grey.shade200,
|
||||
Colors.grey.shade100,
|
||||
Colors.grey.shade200,
|
||||
],
|
||||
stops: [
|
||||
(_ctrl.value - 0.3).clamp(0.0, 1.0),
|
||||
_ctrl.value.clamp(0.0, 1.0),
|
||||
(_ctrl.value + 0.3).clamp(0.0, 1.0),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
596
lib/view/dashboard_view/tenant_profile.dart
Normal file
596
lib/view/dashboard_view/tenant_profile.dart
Normal file
@@ -0,0 +1,596 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:nearledaily/constants/color_constants.dart';
|
||||
import '../../constants/font_constants.dart';
|
||||
import '../../widgets/text_widget.dart';
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// MODEL
|
||||
// ─────────────────────────────────────────────
|
||||
class TenantDetails {
|
||||
final int tenantid;
|
||||
final String tenantname;
|
||||
final String tenanttype; // "D" = delivery-only
|
||||
final String registrationno;
|
||||
final String companyname;
|
||||
final String primaryemail;
|
||||
final String primarycontact;
|
||||
final String address;
|
||||
final String city;
|
||||
final String state;
|
||||
final String postcode;
|
||||
final String latitude;
|
||||
final String longitude;
|
||||
final String status; // "Active" / else
|
||||
|
||||
const TenantDetails({
|
||||
required this.tenantid,
|
||||
required this.tenantname,
|
||||
required this.tenanttype,
|
||||
required this.registrationno,
|
||||
required this.companyname,
|
||||
required this.primaryemail,
|
||||
required this.primarycontact,
|
||||
required this.address,
|
||||
required this.city,
|
||||
required this.state,
|
||||
required this.postcode,
|
||||
required this.latitude,
|
||||
required this.longitude,
|
||||
required this.status,
|
||||
});
|
||||
|
||||
factory TenantDetails.fromJson(Map<String, dynamic> j) => TenantDetails(
|
||||
tenantid: j['tenantid'] ?? 0,
|
||||
tenantname: j['tenantname'] ?? '',
|
||||
tenanttype: j['tenanttype'] ?? '',
|
||||
registrationno: j['registrationno'] ?? '',
|
||||
companyname: j['companyname'] ?? '',
|
||||
primaryemail: j['primaryemail'] ?? '',
|
||||
primarycontact: j['primarycontact'] ?? '',
|
||||
address: j['address'] ?? '',
|
||||
city: j['city'] ?? '',
|
||||
state: j['state'] ?? '',
|
||||
postcode: j['postcode'] ?? '',
|
||||
latitude: j['latitude'] ?? '',
|
||||
longitude: j['longitude'] ?? '',
|
||||
status: j['status'] ?? '',
|
||||
);
|
||||
|
||||
bool get isDeliveryOnly => tenanttype == 'D';
|
||||
bool get isActive => status == 'Active';
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// API SERVICE
|
||||
// ─────────────────────────────────────────────
|
||||
class TenantApiService {
|
||||
static Future<TenantDetails> fetch(int tenantId) async {
|
||||
final res = await http.get(Uri.parse(
|
||||
'https://fiesta.nearle.app/live/api/v1/mob/tenants/gettenantinfo/?tenantid=$tenantId'));
|
||||
if (res.statusCode == 200) {
|
||||
final body = jsonDecode(res.body);
|
||||
if (body['status'] == true) {
|
||||
return TenantDetails.fromJson(body['details']);
|
||||
}
|
||||
throw Exception(body['message']);
|
||||
}
|
||||
throw Exception('HTTP ${res.statusCode}');
|
||||
}
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
// SCREEN
|
||||
// ─────────────────────────────────────────────
|
||||
class StoreOverviewScreen extends StatefulWidget {
|
||||
final int tenantId;
|
||||
const StoreOverviewScreen({super.key, this.tenantId = 1091});
|
||||
|
||||
@override
|
||||
State<StoreOverviewScreen> createState() => _StoreOverviewScreenState();
|
||||
}
|
||||
|
||||
class _StoreOverviewScreenState extends State<StoreOverviewScreen> {
|
||||
late Future<TenantDetails> _future;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_future = TenantApiService.fetch(widget.tenantId);
|
||||
}
|
||||
|
||||
// ── Dialer ───────────────────────────────────
|
||||
Future<void> _launchDialer(String phone) async {
|
||||
final uri = Uri(scheme: 'tel', path: phone);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
await launchUrl(uri);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Could not open dialer')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Maps ─────────────────────────────────────
|
||||
Future<void> _openMap(String lat, String lng, String label) async {
|
||||
final encoded = Uri.encodeComponent(label);
|
||||
final uri = Uri.parse(
|
||||
'https://www.google.com/maps/search/?api=1&query=$lat,$lng($encoded)',
|
||||
);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Could not open maps')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Bad-experience bottom sheet ──────────────────
|
||||
void _showBadExperienceSheet(TenantDetails tenant) {
|
||||
final reasons = [
|
||||
'Wrong items delivered',
|
||||
'Poor food quality',
|
||||
'Late delivery',
|
||||
'Rude behaviour',
|
||||
'Other',
|
||||
];
|
||||
String? selected;
|
||||
|
||||
showModalBottomSheet(
|
||||
backgroundColor: Colors.white,
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
|
||||
),
|
||||
builder: (_) => StatefulBuilder(
|
||||
builder: (ctx, setSheet) => Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: 20,
|
||||
right: 20,
|
||||
top: 20,
|
||||
bottom: MediaQuery.of(ctx).viewInsets.bottom + 24,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Handle bar
|
||||
Center(
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade300,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
ReusableTextWidget(
|
||||
text: 'What went wrong?',
|
||||
color: Colors.black87,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
ReusableTextWidget(
|
||||
text: 'Tell us about your experience at ${tenant.tenantname}',
|
||||
color: Colors.grey,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Reason chips
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: reasons.map((r) {
|
||||
final picked = selected == r;
|
||||
return GestureDetector(
|
||||
onTap: () => setSheet(() => selected = r),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: picked
|
||||
? const Color(0xFF6A1B9A)
|
||||
: Colors.grey.shade100,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: picked
|
||||
? const Color(0xFF6A1B9A)
|
||||
: Colors.grey.shade300,
|
||||
),
|
||||
),
|
||||
child: ReusableTextWidget(
|
||||
text: r,
|
||||
color: picked ? Colors.white : Colors.black87,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Hide store option
|
||||
|
||||
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// Submit button
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF6A1B9A),
|
||||
disabledBackgroundColor: Colors.grey.shade200,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(13),
|
||||
),
|
||||
),
|
||||
onPressed: selected == null
|
||||
? null
|
||||
: () {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Feedback submitted: $selected'),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: ReusableTextWidget(
|
||||
text: 'Submit Feedback',
|
||||
color: selected == null ? Colors.grey : Colors.white,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Color(0xFFF9F9F9), Color(0xFFF1F1F1)],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: FutureBuilder<TenantDetails>(
|
||||
future: _future,
|
||||
builder: (context, snap) {
|
||||
if (snap.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (snap.hasError) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.error_outline,
|
||||
color: Colors.red, size: 48),
|
||||
const SizedBox(height: 12),
|
||||
Text('Failed to load\n${snap.error}',
|
||||
textAlign: TextAlign.center),
|
||||
const SizedBox(height: 12),
|
||||
ElevatedButton(
|
||||
onPressed: () => setState(
|
||||
() => _future = TenantApiService.fetch(widget.tenantId)),
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final t = snap.data!;
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
children: [
|
||||
_topBar(),
|
||||
const SizedBox(height: 16),
|
||||
_storeCard(t),
|
||||
const SizedBox(height: 12),
|
||||
_badExperienceCard(t),
|
||||
const SizedBox(height: 12),
|
||||
_legalCard(t),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_bottomButton(),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ── Top bar ──────────────────────────────────
|
||||
Widget _topBar() => Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
backgroundColor: Colors.white,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
|
||||
],
|
||||
);
|
||||
|
||||
// ── Store card ───────────────────────────────
|
||||
Widget _storeCard(TenantDetails t) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: _card(),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// tenantname
|
||||
ReusableTextWidget(
|
||||
text: t.tenantname,
|
||||
color: Colors.black.withOpacity(0.75),
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 23,
|
||||
fontWeight: FontWeight.bold,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// address
|
||||
ReusableTextWidget(
|
||||
text: t.address,
|
||||
color: Colors.black87,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Call & Directions
|
||||
Row(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => _launchDialer(t.primarycontact),
|
||||
child: _circleIcon(Icons.call),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
GestureDetector(
|
||||
onTap: () => _openMap(t.latitude, t.longitude, t.tenantname),
|
||||
child: _circleIcon(Icons.near_me_outlined),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const Divider(height: 24, thickness: 0.5),
|
||||
|
||||
// status → Open / Closed
|
||||
_infoRow(
|
||||
icon: Icons.access_time,
|
||||
title: t.isActive ? 'Open now' : 'Currently Closed',
|
||||
titleColor: t.isActive ? Colors.green : Colors.red,
|
||||
),
|
||||
|
||||
// tenanttype == "D" → delivery-only row
|
||||
if (t.isDeliveryOnly) ...[
|
||||
const Divider(thickness: 0.5),
|
||||
_infoRow(
|
||||
icon: Icons.store_mall_directory_outlined,
|
||||
title: 'This is a delivery-only kitchen',
|
||||
subtitle:
|
||||
'There are multiple brands delivering from this kitchen',
|
||||
),
|
||||
],
|
||||
|
||||
const Divider(thickness: 0.5),
|
||||
|
||||
// city + state + postcode
|
||||
_infoRow(
|
||||
icon: Icons.location_city_outlined,
|
||||
title: '${t.city}, ${t.state} – ${t.postcode}',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ── Bad experience card ──────────────────────
|
||||
Widget _badExperienceCard(TenantDetails t) => Container(
|
||||
decoration: _card(),
|
||||
child: ListTile(
|
||||
leading: Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red.shade50,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(Icons.sentiment_dissatisfied_outlined,
|
||||
color: Colors.red.shade400, size: 20),
|
||||
),
|
||||
title: ReusableTextWidget(
|
||||
text: 'Had a bad experience here?',
|
||||
color: Colors.black87,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
subtitle: ReusableTextWidget(
|
||||
text: 'Report an issue or hide this store',
|
||||
color: Colors.black54,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
trailing: const Icon(Icons.chevron_right, color: Colors.black87),
|
||||
onTap: () => _showBadExperienceSheet(t),
|
||||
),
|
||||
);
|
||||
|
||||
// ── Legal card — only real non-empty API fields ──
|
||||
Widget _legalCard(TenantDetails t) => Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: _card(),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_labelText('Legal Name', t.companyname),
|
||||
const SizedBox(height: 12),
|
||||
_labelText('GST Number', t.registrationno),
|
||||
const SizedBox(height: 12),
|
||||
_labelText('Contact', t.primarycontact),
|
||||
const SizedBox(height: 12),
|
||||
_labelText('Email', t.primaryemail),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
// ── Bottom button ────────────────────────────
|
||||
Widget _bottomButton() => Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 10, 16, 13),
|
||||
color: Colors.white,
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF6A1B9A),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(13)),
|
||||
),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: ReusableTextWidget(
|
||||
text: 'Go back to menu',
|
||||
color: Colors.white,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// ── Helpers ──────────────────────────────────
|
||||
Widget _circleIcon(IconData icon) => Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.white,
|
||||
border: Border.all(color: Colors.grey.shade200),
|
||||
),
|
||||
child: Center(
|
||||
child: Icon(icon, size: 22, color: ColorConstants.primaryColor),
|
||||
),
|
||||
);
|
||||
|
||||
Widget _infoRow({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
String? subtitle,
|
||||
Color? titleColor,
|
||||
}) =>
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(icon, size: 20, color: Colors.black87),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ReusableTextWidget(
|
||||
text: title,
|
||||
color: titleColor ?? Colors.black87,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
if (subtitle != null)
|
||||
ReusableTextWidget(
|
||||
text: subtitle,
|
||||
color: Colors.grey,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
maxLines: 2,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, color: Colors.black87),
|
||||
],
|
||||
);
|
||||
|
||||
Widget _labelText(String label, String value) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ReusableTextWidget(
|
||||
text: label,
|
||||
color: Colors.grey,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
ReusableTextWidget(
|
||||
text: value,
|
||||
color: Colors.black87,
|
||||
fontFamily: FontConstants.fontFamily,
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
BoxDecoration _card() => BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.04),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user