175 lines
5.8 KiB
Dart
175 lines
5.8 KiB
Dart
import 'package:citycards_customer/networkApiServices/api_urls.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import '../core/route_constants.dart';
|
|
import '../home/widgets/search_city_bottomsheet.dart';
|
|
import '../localPreference/local_preference.dart';
|
|
import '../profile/bloc/profile/profile_bloc.dart';
|
|
import '../profile/bloc/profile/profile_state.dart';
|
|
|
|
class CommonAppBar extends StatelessWidget {
|
|
const CommonAppBar({
|
|
super.key,
|
|
required this.isWhiteLogo,
|
|
required this.isProfilePage,
|
|
this.showCart = true,
|
|
required this.showDivider,
|
|
this.imageUrl,
|
|
this.isSelectCity = false,
|
|
});
|
|
|
|
final bool isWhiteLogo;
|
|
final bool isProfilePage;
|
|
final bool? showCart;
|
|
final bool showDivider;
|
|
final String? imageUrl;
|
|
final bool isSelectCity;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final bool isPathIcon =
|
|
imageUrl != null && imageUrl!.isNotEmpty;
|
|
|
|
return Column(
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
/// LEFT SIDE
|
|
Row(
|
|
children: [
|
|
/// ✅ LOGO / PATH ICON (SIZE CONTROLLED)
|
|
SizedBox(
|
|
height: isPathIcon ? 40.h : 32.h, // 🔥 ONLY path icon bigger
|
|
child: isPathIcon
|
|
? Image.network(
|
|
imageUrl!,
|
|
fit: BoxFit.contain,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
return Image.asset(
|
|
isWhiteLogo
|
|
? "assets/logo/logo_city_cards_white.png"
|
|
: "assets/logo/logo_city_cards.png",
|
|
fit: BoxFit.contain,
|
|
);
|
|
},
|
|
)
|
|
: Image.asset(
|
|
isWhiteLogo
|
|
? "assets/logo/logo_city_cards_white.png"
|
|
: "assets/logo/logo_city_cards.png",
|
|
fit: BoxFit.contain,
|
|
),
|
|
),
|
|
|
|
/// ✅ CITY DROPDOWN
|
|
if (isSelectCity)
|
|
IconButton(
|
|
onPressed: () {
|
|
showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
backgroundColor: Colors.transparent,
|
|
builder: (_) => const CitySelectionBottomSheet(),
|
|
);
|
|
},
|
|
icon: Icon(
|
|
Icons.arrow_drop_down,
|
|
color: isWhiteLogo
|
|
? Colors.white
|
|
: const Color(0xffF95F62),
|
|
size: 30,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
/// RIGHT SIDE
|
|
Row(
|
|
children: [
|
|
if (showCart!)
|
|
InkWell(
|
|
onTap: () {
|
|
Navigator.of(
|
|
context,
|
|
rootNavigator: true,
|
|
).pushNamed(RouteConstants.cartPage);
|
|
},
|
|
child: Container(
|
|
padding: const EdgeInsets.all(10),
|
|
decoration: const BoxDecoration(
|
|
color: Colors.white,
|
|
shape: BoxShape.circle,
|
|
),
|
|
child: Image.asset(
|
|
"assets/icons/shopping_cart.png",
|
|
height: 20.h,
|
|
),
|
|
),
|
|
),
|
|
|
|
SizedBox(width: 8.w),
|
|
|
|
if (!isProfilePage)
|
|
GestureDetector(
|
|
onTap: () {
|
|
Navigator.of(
|
|
context,
|
|
rootNavigator: true,
|
|
).pushNamed(RouteConstants.profile);
|
|
},
|
|
child: BlocBuilder<ProfileBloc, ProfileState>(
|
|
builder: (context, state) {
|
|
String? imagePath;
|
|
|
|
// ✅ Get image from profile state
|
|
if (state is ProfileLoaded) {
|
|
imagePath = state.profile.profileImage;
|
|
}
|
|
|
|
// ✅ Build full image URL
|
|
final String? imageUrl =
|
|
(imagePath != null && imagePath.isNotEmpty)
|
|
? "${ApiUrls.baseUrl}$imagePath"
|
|
: null;
|
|
|
|
return CircleAvatar(
|
|
radius: 20.r,
|
|
backgroundColor: const Color(0xffFFDFDF),
|
|
|
|
// ✅ Network image only if exists
|
|
backgroundImage:
|
|
(imageUrl != null && imageUrl.isNotEmpty)
|
|
? NetworkImage(imageUrl)
|
|
: null,
|
|
|
|
// ✅ Default fallback (unchanged)
|
|
child: (imageUrl == null || imageUrl.isEmpty)
|
|
? Image.asset(
|
|
"assets/images/profile_default_img.png",
|
|
)
|
|
: null,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
/// DIVIDER
|
|
if (showDivider)
|
|
Column(
|
|
children: [
|
|
SizedBox(height: 12.h),
|
|
const Divider(height: 1, color: Color(0xFFD9D9D9)),
|
|
SizedBox(height: 22.h),
|
|
],
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|