Update project

This commit is contained in:
2026-07-23 15:36:11 +05:30
parent 1197cfc161
commit 14fffa40c6
84 changed files with 20918 additions and 2761 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:animations/animations.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/cupertino.dart';
@@ -27,8 +28,12 @@ import '../../controllers/cart_controller/cart.dart';
import '../../controllers/dashboard_controller/category.dart';
import '../../controllers/dashboard_controller/dashboard_controller.dart';
import '../../controllers/product/product_controller.dart';
import '../../controllers/tenant_controller /tenant_list.dart';
import '../../controllers/tenant_list/tenant_controller.dart';
import '../../domain/repository/authentication/auth_repository.dart';
import '../../features/Products/product_card.dart';
import '../../modules/search_model/search_model.dart';
import '../../service/firebase_analytics/analytics_service.dart';
import '../../widgets/fav_button.dart';
import '../../widgets/tenantcategory.dart';
import '../../widgets/text_widget.dart';
import '../account/demo.dart';
@@ -37,8 +42,10 @@ import '../cart/cart_view.dart';
import '../home_view.dart';
import '../product/category_products.dart';
import '../product/product_view.dart';
import '../product/products_list.dart' hide ProductItem;
import '../product/tenant_products.dart';
import '../qr_scaner/qr_scaner.dart';
import 'ai_search.dart';
class DashboardPage extends StatefulWidget {
const DashboardPage({super.key});
@@ -72,6 +79,87 @@ class _DashboardPageState extends State<DashboardPage> {
static const _kProfile = 'cached_profile';
final recommendations = [
RecommendedItem(
title: 'Cheapest Pizza\nNearby',
subtitle: 'From ₹149',
image: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS9b5A0dGeZ4PR6cdpuvDyoMa3lO7JBRyMo8Q&s',
bgColor: Color(0xFFFFF3EC),
accentColor: Color(0xFFFF6B2C),
),
RecommendedItem(
title: 'Grocery Basket\n₹320 Less',
subtitle: 'Save more on your order',
image: 'https://images.unsplash.com/photo-1542838132-92c53300491e?w=200&fit=crop',
bgColor: Color(0xFFF0FAF0),
accentColor: Color(0xFF22A45D),
),
RecommendedItem(
title: 'Birthday\nComing Up!',
subtitle: 'Let Nearle plan it',
image: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=200&fit=crop',
bgColor: Color(0xFFFDF0F8),
accentColor: Color(0xFFD63384),
),
];
final products = [
ProductItem(
name: 'Chicken Biryani',
category: 'Food · HotPot',
price: '₹189',
originalPrice: '₹240',
image: 'https://images.unsplash.com/photo-1563379091339-03b21ab4a4f8?w=300&fit=crop',
rating: 4.8,
reviewCount: 320,
),
ProductItem(
name: 'Fresh Veggie Basket',
category: 'Grocery · BigBasket',
price: '₹299',
originalPrice: '₹420',
image: 'https://images.unsplash.com/photo-1512621776951-a57141f2eefd?w=300&fit=crop',
rating: 4.5,
reviewCount: 180,
),
ProductItem(
name: 'Margherita Pizza',
category: 'Food · Dominos',
price: '₹149',
originalPrice: '₹199',
image: 'https://images.unsplash.com/photo-1565299624946-b28f40a0ae38?w=300&fit=crop',
rating: 4.6,
reviewCount: 512,
),
ProductItem(
name: 'Birthday Cake',
category: 'Bakery · CakeZone',
price: '₹549',
originalPrice: '₹699',
image: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=300&fit=crop',
rating: 4.9,
reviewCount: 94,
),
ProductItem(
name: 'Mango Smoothie',
category: 'Drinks · Juice Bar',
price: '₹89',
originalPrice: '₹120',
image: 'https://images.unsplash.com/photo-1623065422902-30a2d299bbe4?w=300&fit=crop',
rating: 4.4,
reviewCount: 67,
),
ProductItem(
name: 'Paneer Butter Masala',
category: 'Food · Behrouz',
price: '₹220',
originalPrice: '₹280',
image: 'https://images.unsplash.com/photo-1631452180519-c014fe946bc7?w=300&fit=crop',
rating: 4.7,
reviewCount: 210,
),
];
bool status = true;
bool _showBackToTop = false;
RxBool showMiniCart = false.obs;
@@ -84,177 +172,6 @@ class _DashboardPageState extends State<DashboardPage> {
Icons.shopping_cart_rounded,
];
void _openCategoryBottomSheet(
BuildContext context,
List subCategories,
item,
) {
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (_) {
return SafeArea(
top: false,
child: ClipRRect(
borderRadius:
const BorderRadius.vertical(top: Radius.circular(20)),
child: Container(
height: MediaQuery.of(context).size.height * 0.85,
color: Colors.white,
child: Column(
children: [
const SizedBox(height: 8),
// drag handle (smaller)
Container(
width: 36,
height: 4,
decoration: BoxDecoration(
color: Colors.grey.shade400,
borderRadius: BorderRadius.circular(10),
),
),
const SizedBox(height: 10),
// Title (not oversized)
const Padding(
padding: EdgeInsets.symmetric(horizontal: 14),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
"Category",
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
),
),
),
),
const SizedBox(height: 10),
Expanded(
child: subCategories.isEmpty
? const Center(
child: Text("No products available"),
)
: GridView.builder(
padding:
const EdgeInsets.fromLTRB(12, 8, 12, 16),
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.78,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemCount: subCategories.length,
itemBuilder: (context, index) {
final product = subCategories[index];
return InkWell(
borderRadius:
BorderRadius.circular(14),
onTap: () {
Navigator.pop(context);
Get.to(
() => SubCategoryProductsScreen(
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:
product.subcatname
.toString(),
),
);
},
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.circular(14),
border: Border.all(
color: Colors.black12,
width: 0.25,
),
boxShadow: [
BoxShadow(
color: Colors.black
.withOpacity(0.04),
blurRadius: 5,
),
],
),
child: Column(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
const SizedBox(height: 10),
ClipOval(
child: Image.network(
product.image ?? '',
width: 100,
height: 100,
fit: BoxFit.cover,
errorBuilder:
(_, __, ___) =>
const Icon(
Icons
.image_not_supported),
),
),
Padding(
padding:
const EdgeInsets.symmetric(
horizontal: 6),
child: ReusableTextWidget(
text:
product.subcatname ??
'',
color: Colors.black
.withOpacity(0.7),
fontFamily:
FontConstants
.fontFamily,
fontSize: 11.5,
fontWeight:
FontWeight.w600,
textAlign:
TextAlign.center,
maxLines: 1,
overflow: TextOverflow
.ellipsis,
),
),
const SizedBox(height: 10),
],
),
),
);
},
),
),
],
),
),
),
);
},
);
}
@override
@@ -659,7 +576,7 @@ class _DashboardPageState extends State<DashboardPage> {
borderRadius: BorderRadius.circular(14),
onTap: () => Get.to(() => const SearchScreen()),
child: Container(
height: 48,
height: 55,
padding: const EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration(
color: Colors.white,
@@ -710,6 +627,11 @@ class _DashboardPageState extends State<DashboardPage> {
],
),
),
IconButton(onPressed: () => Get.to(() => const SearchPage()), icon: const Icon(Icons.mic, color: Colors.black87, size: 22)),
IconButton(onPressed: () => Get.to(() => const SearchPage()), icon: const Icon(Icons.camera_alt_outlined, color: Colors.black87, size: 22)),
],
),
),
@@ -811,12 +733,226 @@ class _DashboardPageState extends State<DashboardPage> {
);
}),
const SliverToBoxAdapter(
child: SizedBox(height: 12),
),
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 16),
sliver: SliverToBoxAdapter(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Recommended for You",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black.withOpacity(0.7),
),
),
TextButton(
onPressed: () {},
child: const Text("See all"),
),
],
),
),
),
SliverToBoxAdapter(
child: SizedBox(
height: 110,
child: ListView.separated(
padding: const EdgeInsets.symmetric(horizontal: 16),
scrollDirection: Axis.horizontal,
itemCount: recommendations.length,
separatorBuilder: (_, __) => const SizedBox(width: 12),
itemBuilder: (context, index) {
final item = recommendations[index];
return Container(
width: 160,
decoration: BoxDecoration(
color: item.bgColor,
borderRadius: BorderRadius.circular(12),
),
child: Stack(
children: [
// Title + Subtitle
Positioned(
top: 14,
left: 14,
right: 14,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
item.title,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w700,
color: Colors.black.withOpacity(0.7),
height: 1.25,
),
),
const SizedBox(height: 6),
Text(
item.subtitle,
style: TextStyle(
fontSize: 9,
fontWeight: FontWeight.w600,
color: item.accentColor,
),
),
],
),
),
// Network image bottom-right
Positioned(
bottom: 0,
right: 0,
child: ClipRRect(
borderRadius: const BorderRadius.only(
bottomRight: Radius.circular(20),
),
child: CachedNetworkImage(
imageUrl: item.image,
width: 80,
height: 80,
fit: BoxFit.contain,
placeholder: (context, url) => const SizedBox(
width: 80,
height: 80,
),
errorWidget: (context, url, error) => SizedBox(
width: 80,
height: 80,
child: Icon(
Icons.image_not_supported_rounded,
color: item.accentColor.withOpacity(0.3),
size: 28,
),
),
),
),
),
// Arrow button bottom-right corner
Positioned(
bottom: 10,
right: 10,
child: Container(
width: 26,
height: 26,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
blurRadius: 6,
offset: const Offset(0, 2),
),
],
),
child: Icon(
Icons.chevron_right_rounded,
size: 16,
color: item.accentColor,
),
),
),
],
),
);
},
),
),
),
const SliverToBoxAdapter(
child: SizedBox(height: 12),
),
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 16),
sliver: SliverToBoxAdapter(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Fresh picks for you",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black.withOpacity(0.7),
),
),
TextButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context,) => const ProductsList()));
},
child: const Text("See all"),
),
],
),
),
),
const SliverToBoxAdapter(
child: SizedBox(height: 12),
),
SliverPadding(
padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),
sliver: SliverGrid(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
crossAxisSpacing: 12,
mainAxisSpacing: 12,
mainAxisExtent: 270,
),
delegate: SliverChildBuilderDelegate(
(context, index) => ProductCard(item: products[index]),
childCount: products.length,
),
),
),
const SliverToBoxAdapter(
child: SizedBox(height: 12),
),
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 16),
sliver: SliverToBoxAdapter(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Near by Stores",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black.withOpacity(0.7),
),
),
TextButton(
onPressed: () {},
child: const Text("See all"),
),
],
),
),
),
@@ -898,7 +1034,7 @@ class _DashboardPageState extends State<DashboardPage> {
(context, index) {
final item = tenantController.tenants[index];
return _ZoomOnTap(
onTap: () {
onTap: () async {
Get.to(() => ProductsScreen(
tenantId: item.tenantid!,
locationId: item.locationid!,
@@ -910,6 +1046,16 @@ class _DashboardPageState extends State<DashboardPage> {
tenantloc:item.locationid!,
subCategoryName: "",
));
await AnalyticsService.logEvent(
'store_viewed',
parameters: {
'store_id': item.tenantid!,
'store_name': item.tenantname!,
'locatiom' : item.locationname!,
},
);
},
child: Container(
margin: const EdgeInsets.only(bottom: 12, top: 12),
@@ -1063,7 +1209,7 @@ class _DashboardPageState extends State<DashboardPage> {
maxLines: 1,
),
IconButton(
onPressed: () {
onPressed: () async {
// _openCategoryBottomSheet(
// context,
// item.subcategories ?? [],
@@ -1082,6 +1228,15 @@ class _DashboardPageState extends State<DashboardPage> {
subCategoryName: "",
));
await AnalyticsService.logEvent(
'store_viewed',
parameters: {
'store_id': item.tenantid!,
'store_name': item.tenantname!,
'locatiom' : item.locationname!,
},
);
},
icon: Icon(Icons.arrow_circle_right_outlined,
color: Colors.black.withOpacity(0.6),
@@ -1113,7 +1268,7 @@ class _DashboardPageState extends State<DashboardPage> {
final product = item.subcategories![index];
return InkWell(
borderRadius: BorderRadius.circular(16),
onTap: () {
onTap: () async {
// Get.to(() => SubCategoryProductsScreen(
// tenantId: item.tenantid!,
@@ -1139,6 +1294,15 @@ class _DashboardPageState extends State<DashboardPage> {
subCategoryName: "",
));
await AnalyticsService.logEvent(
'store_viewed',
parameters: {
'store_id': item.tenantid!,
'store_name': item.tenantname!,
'locatiom' : item.locationname!,
},
);
},
child: Container(
margin:
@@ -1247,11 +1411,6 @@ class _DashboardPageState extends State<DashboardPage> {
),
),
),
Obx(() {
if (cartController.cartItems.isEmpty) return const SizedBox();
final tenant = cartController.currentTenant.value;
@@ -1374,45 +1533,12 @@ class _DashboardPageState extends State<DashboardPage> {
),
);
}),
],),
),
);
}
Widget _chip(String emoji, String label) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: Color(0xFFF8F4FF),
borderRadius: BorderRadius.circular(30),
border: Border.all(color: Color(0xFFE0D4FF), width: 1),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(emoji, style: TextStyle(fontSize: 13)),
SizedBox(width: 5),
Text(
label,
style: TextStyle(fontSize: 11, fontWeight: FontWeight.w500, color: Color(0xFF333333)),
),
],
),
);
}
@@ -1628,23 +1754,6 @@ class _DashboardPageState extends State<DashboardPage> {
);
}
Widget _buildBannerShimmer() {
return SliverToBoxAdapter(
child: Shimmer.fromColors(
baseColor: Colors.grey.shade300,
highlightColor: Colors.grey.shade100,
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
height: 180,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.circular(14),
),
),
),
);
}
Widget _buildListShimmer(BuildContext context) {
return SliverList(
@@ -1834,4 +1943,5 @@ class _ZoomOnTapState extends State<_ZoomOnTap> {
),
);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -81,6 +81,210 @@ class TenantApiService {
}
}
// ─────────────────────────────────────────────
// SHIMMER WIDGET
// ─────────────────────────────────────────────
class _ShimmerBox extends StatefulWidget {
final double width;
final double height;
final double borderRadius;
const _ShimmerBox({
required this.width,
required this.height,
this.borderRadius = 8,
});
@override
State<_ShimmerBox> createState() => _ShimmerBoxState();
}
class _ShimmerBoxState extends State<_ShimmerBox>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _animation;
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 1200),
)..repeat();
_animation = Tween<double>(begin: -1.5, end: 1.5).animate(
CurvedAnimation(parent: _controller, curve: Curves.easeInOutSine),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _animation,
builder: (_, __) => Container(
width: widget.width,
height: widget.height,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(widget.borderRadius),
gradient: LinearGradient(
begin: Alignment(_animation.value - 1, 0),
end: Alignment(_animation.value, 0),
colors: const [
Color(0xFFE8E8E8),
Color(0xFFF5F5F5),
Color(0xFFE8E8E8),
],
),
),
),
);
}
}
// Shimmer skeleton that mimics the actual screen layout
class _StoreOverviewShimmer extends StatelessWidget {
const _StoreOverviewShimmer();
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Top bar
Row(
children: [
_ShimmerBox(width: 40, height: 40, borderRadius: 20),
],
),
const SizedBox(height: 16),
// Store card shimmer
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.04),
blurRadius: 10,
offset: const Offset(0, 4),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_ShimmerBox(width: 200, height: 22, borderRadius: 6),
const SizedBox(height: 10),
_ShimmerBox(width: double.infinity, height: 13, borderRadius: 4),
const SizedBox(height: 6),
_ShimmerBox(width: 160, height: 13, borderRadius: 4),
const SizedBox(height: 14),
Row(
children: [
_ShimmerBox(width: 40, height: 40, borderRadius: 20),
const SizedBox(width: 12),
_ShimmerBox(width: 40, height: 40, borderRadius: 20),
],
),
const Divider(height: 24, thickness: 0.5),
Row(
children: [
_ShimmerBox(width: 20, height: 20, borderRadius: 4),
const SizedBox(width: 12),
_ShimmerBox(width: 100, height: 13, borderRadius: 4),
],
),
const Divider(height: 24, thickness: 0.5),
Row(
children: [
_ShimmerBox(width: 20, height: 20, borderRadius: 4),
const SizedBox(width: 12),
_ShimmerBox(width: 150, height: 13, borderRadius: 4),
],
),
],
),
),
const SizedBox(height: 12),
// Bad experience card shimmer
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.04),
blurRadius: 10,
offset: const Offset(0, 4),
),
],
),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
child: Row(
children: [
_ShimmerBox(width: 36, height: 36, borderRadius: 18),
const SizedBox(width: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_ShimmerBox(width: 180, height: 13, borderRadius: 4),
const SizedBox(height: 6),
_ShimmerBox(width: 140, height: 11, borderRadius: 4),
],
),
],
),
),
const SizedBox(height: 12),
// Legal card shimmer
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.04),
blurRadius: 10,
offset: const Offset(0, 4),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: List.generate(4, (i) => Padding(
padding: EdgeInsets.only(bottom: i < 3 ? 16.0 : 0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_ShimmerBox(width: 80, height: 11, borderRadius: 4),
const SizedBox(height: 5),
_ShimmerBox(width: 160, height: 13, borderRadius: 4),
],
),
)),
),
),
],
),
);
}
}
// ─────────────────────────────────────────────
// SCREEN
// ─────────────────────────────────────────────
@@ -285,9 +489,16 @@ class _StoreOverviewScreenState extends State<StoreOverviewScreen> {
child: FutureBuilder<TenantDetails>(
future: _future,
builder: (context, snap) {
// ── SHIMMER while loading ──────────────
if (snap.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
return Column(
children: [
Expanded(child: const _StoreOverviewShimmer()),
_bottomButton(),
],
);
}
if (snap.hasError) {
return Center(
child: Column(

View File

@@ -0,0 +1,560 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
// ─────────────────────────────────────────────
// CONFIG — change IP to your Mac's local IP
// Run: ipconfig getifaddr en0
// ─────────────────────────────────────────────
const String kBaseUrl = 'http://192.168.1.XXX:8000';
const int kCustomerId = 6060;
const double kLatitude = 11.0168;
const double kLongitude = 76.9558;
// ─────────────────────────────────────────────
// API SERVICE
// ─────────────────────────────────────────────
class AgentService {
static Future<Map<String, dynamic>> findIngredients(String userInput) async {
final res = await http.post(
Uri.parse('$kBaseUrl/find-ingredients'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'user_input': userInput,
'customer_id': kCustomerId,
'latitude': kLatitude,
'longitude': kLongitude,
}),
);
return jsonDecode(res.body);
}
static Future<Map<String, dynamic>> chat(
String message,
List conversationHistory,
) async {
final res = await http.post(
Uri.parse('$kBaseUrl/chat'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'message': message,
'customer_id': kCustomerId,
'latitude': kLatitude,
'longitude': kLongitude,
'conversation_history': conversationHistory,
}),
);
return jsonDecode(res.body);
}
static Future<Map<String, dynamic>> clarify(
String originalInput,
String clarification,
) async {
final res = await http.post(
Uri.parse('$kBaseUrl/clarify'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'original_input': originalInput,
'clarification': clarification,
'customer_id': kCustomerId,
'latitude': kLatitude,
'longitude': kLongitude,
}),
);
return jsonDecode(res.body);
}
}
// ─────────────────────────────────────────────
// SEARCH SCREEN
// ─────────────────────────────────────────────
class SearchScreen extends StatefulWidget {
const SearchScreen({super.key});
@override
State<SearchScreen> createState() => _SearchScreenState();
}
class _SearchScreenState extends State<SearchScreen> {
final TextEditingController _searchController = TextEditingController();
final FocusNode _focusNode = FocusNode();
bool _isLoading = false;
String? _agentMessage;
String? _clarificationQuestion;
String? _lastInput;
List _ingredients = [];
List _stores = [];
// Quick suggestion chips
final List<String> _suggestions = [
'🍓 Strawberry',
'🍗 Biryani',
'🤒 Fever medicine',
'🍳 Cook sambar',
'🥛 Milk',
'😴 Bored snacks',
];
// ── Search via /find-ingredients ──────────────────────────
Future<void> _search(String input) async {
if (input.trim().isEmpty) return;
FocusScope.of(context).unfocus();
setState(() {
_isLoading = true;
_agentMessage = null;
_clarificationQuestion = null;
_stores = [];
_ingredients = [];
_lastInput = input;
});
try {
final result = await AgentService.findIngredients(input);
if (result['status'] == 'needs_clarification') {
setState(() {
_clarificationQuestion = result['question'];
_isLoading = false;
});
return;
}
setState(() {
_agentMessage = result['agent_message'];
_ingredients = result['ingredients_needed'] ?? [];
_stores = result['stores'] ?? [];
_isLoading = false;
});
} catch (e) {
setState(() {
_agentMessage = 'Something went wrong. Please try again.';
_isLoading = false;
});
}
}
// ── Answer agent clarification ────────────────────────────
Future<void> _answerClarification(String answer) async {
setState(() {
_clarificationQuestion = null;
_isLoading = true;
});
try {
final result = await AgentService.clarify(_lastInput ?? '', answer);
setState(() {
_agentMessage = result['agent_message'];
_ingredients = result['ingredients_needed'] ?? [];
_stores = result['stores'] ?? [];
_isLoading = false;
});
} catch (e) {
setState(() {
_agentMessage = 'Something went wrong.';
_isLoading = false;
});
}
}
// ─────────────────────────────────────────────────────────
// BUILD
// ─────────────────────────────────────────────────────────
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF5F5F5),
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
title: const Text(
'Nearle',
style: TextStyle(
color: Color(0xFF1A1A1A),
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
centerTitle: false,
),
body: Column(
children: [
// ── Search Bar ──────────────────────────────────
Container(
color: Colors.white,
padding: const EdgeInsets.fromLTRB(16, 8, 16, 16),
child: Row(
children: [
Expanded(
child: TextField(
controller: _searchController,
focusNode: _focusNode,
onSubmitted: _search,
decoration: InputDecoration(
hintText: 'Search or ask anything...',
hintStyle: TextStyle(color: Colors.grey[400]),
prefixIcon: const Icon(Icons.search, color: Color(0xFF6C63FF)),
filled: true,
fillColor: const Color(0xFFF0EFFF),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide.none,
),
contentPadding: const EdgeInsets.symmetric(vertical: 14),
),
),
),
const SizedBox(width: 10),
GestureDetector(
onTap: () => _search(_searchController.text),
child: Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: const Color(0xFF6C63FF),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(Icons.arrow_forward, color: Colors.white, size: 20),
),
),
],
),
),
// ── Suggestion Chips ────────────────────────────
if (_stores.isEmpty && !_isLoading && _clarificationQuestion == null)
SizedBox(
height: 48,
child: ListView.separated(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 16),
itemCount: _suggestions.length,
separatorBuilder: (_, __) => const SizedBox(width: 8),
itemBuilder: (context, i) {
return GestureDetector(
onTap: () {
final text = _suggestions[i].replaceAll(RegExp(r'[^\w\s]'), '').trim();
_searchController.text = text;
_search(text);
},
child: Chip(
label: Text(
_suggestions[i],
style: const TextStyle(fontSize: 13),
),
backgroundColor: Colors.white,
side: const BorderSide(color: Color(0xFFE0E0E0)),
),
);
},
),
),
const SizedBox(height: 8),
// ── Body ────────────────────────────────────────
Expanded(
child: _isLoading
? const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(color: Color(0xFF6C63FF)),
SizedBox(height: 16),
Text('Anna is finding the best deals...', style: TextStyle(color: Colors.grey)),
],
),
)
: _clarificationQuestion != null
? _buildClarification()
: _stores.isEmpty
? _buildEmpty()
: _buildResults(),
),
],
),
);
}
// ── Clarification UI ──────────────────────────────────────
Widget _buildClarification() {
final answerController = TextEditingController();
return Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xFFEDE9FF),
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
const Text('🤔', style: TextStyle(fontSize: 24)),
const SizedBox(width: 12),
Expanded(
child: Text(
_clarificationQuestion!,
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w500),
),
),
],
),
),
const SizedBox(height: 16),
TextField(
controller: answerController,
decoration: InputDecoration(
hintText: 'Type your answer...',
filled: true,
fillColor: Colors.white,
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none),
),
onSubmitted: _answerClarification,
),
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () => _answerClarification(answerController.text),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF6C63FF),
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
child: const Text('Send', style: TextStyle(color: Colors.white, fontSize: 16)),
),
),
],
),
);
}
// ── Empty State ───────────────────────────────────────────
Widget _buildEmpty() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('🛒', style: TextStyle(fontSize: 60)),
const SizedBox(height: 16),
Text(
_agentMessage ?? 'Search for anything\nfrom nearby stores',
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 16, color: Colors.grey),
),
],
),
);
}
// ── Results ───────────────────────────────────────────────
Widget _buildResults() {
return ListView(
padding: const EdgeInsets.all(16),
children: [
// Agent message
if (_agentMessage != null)
Container(
margin: const EdgeInsets.only(bottom: 16),
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: const Color(0xFFEDE9FF),
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
const Text('', style: TextStyle(fontSize: 20)),
const SizedBox(width: 10),
Expanded(child: Text(_agentMessage!, style: const TextStyle(fontSize: 14))),
],
),
),
// Store cards
..._stores.map((storeData) => _StoreCard(storeData: storeData)),
],
);
}
}
// ─────────────────────────────────────────────
// STORE CARD WIDGET
// ─────────────────────────────────────────────
class _StoreCard extends StatelessWidget {
final Map storeData;
const _StoreCard({required this.storeData});
@override
Widget build(BuildContext context) {
final store = storeData['store'] as Map;
final products = storeData['matched_products'] as List;
final savings = store['total_savings'] ?? 0;
final total = store['total_discounted_price'] ?? 0;
final hasOffers = store['has_offers'] == true;
return Container(
margin: const EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10, offset: const Offset(0, 2))],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Store header
Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: const Color(0xFFF0EFFF),
borderRadius: BorderRadius.circular(10),
),
child: const Icon(Icons.store, color: Color(0xFF6C63FF), size: 20),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
store['tenantname'] ?? '',
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
),
Text(
store['locationname'] ?? '',
style: const TextStyle(color: Colors.grey, fontSize: 13),
),
],
),
),
if (hasOffers)
Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: const Color(0xFFE8F5E9),
borderRadius: BorderRadius.circular(20),
),
child: Text(
'Save ₹${savings.toStringAsFixed(0)}',
style: const TextStyle(color: Color(0xFF2E7D32), fontWeight: FontWeight.bold, fontSize: 12),
),
),
],
),
),
const Divider(height: 1),
// Products
...products.map((m) => _ProductRow(matched: m)),
const Divider(height: 1),
// Total + Order button
Padding(
padding: const EdgeInsets.all(16),
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('Total', style: TextStyle(color: Colors.grey, fontSize: 12)),
Text(
'${total.toStringAsFixed(2)}',
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: Color(0xFF1A1A1A)),
),
],
),
const Spacer(),
ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF6C63FF),
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
),
child: const Text('Order Now', style: TextStyle(color: Colors.white)),
),
],
),
),
],
),
);
}
}
// ─────────────────────────────────────────────
// PRODUCT ROW WIDGET
// ─────────────────────────────────────────────
class _ProductRow extends StatelessWidget {
final Map matched;
const _ProductRow({required this.matched});
@override
Widget build(BuildContext context) {
final product = matched['product'] as Map;
final emoji = matched['emoji'] ?? '🛒';
final name = product['productname'] ?? matched['ingredient'] ?? '';
final price = product['discounted_price'] ?? 0;
final original = product['original_price'] ?? 0;
final hasOffer = product['has_offer'] == true;
final discount = product['discount_percent'] ?? 0;
final quantity = matched['quantity'] ?? '';
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
child: Row(
children: [
Text(emoji, style: const TextStyle(fontSize: 24)),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(name, style: const TextStyle(fontWeight: FontWeight.w600, fontSize: 14)),
Text(quantity, style: const TextStyle(color: Colors.grey, fontSize: 12)),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'${price.toStringAsFixed(2)}',
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14, color: Color(0xFF1A1A1A)),
),
if (hasOffer)
Row(
children: [
Text(
'${original.toStringAsFixed(0)}',
style: const TextStyle(
color: Colors.grey,
fontSize: 11,
decoration: TextDecoration.lineThrough,
),
),
const SizedBox(width: 4),
Text(
'$discount% off',
style: const TextStyle(color: Color(0xFF2E7D32), fontSize: 11, fontWeight: FontWeight.bold),
),
],
),
],
),
],
),
);
}
}