sapaly_store/lib/features/screens/details/details.dart

291 lines
12 KiB
Dart

import 'package:adaptix/adaptix.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:sapaly_shop/common/custom_button.dart';
import 'package:sapaly_shop/common/photo.dart';
import 'package:sapaly_shop/constants/global_variables.dart';
import 'package:sapaly_shop/constants/utils.dart';
import 'package:sapaly_shop/features/services/page_navigator.dart';
import 'package:sapaly_shop/features/widgets/sapaly_app_bar.dart';
import 'package:sapaly_shop/models/details_model.dart';
import 'package:sapaly_shop/models/settings_model.dart';
import 'package:sapaly_shop/features/services/requests.dart';
import 'package:sapaly_shop/themes/app_theme.dart';
class Details extends StatefulWidget {
const Details({
super.key,
required this.id,
required this.image,
required this.description,
required this.price,
});
final int id;
final String image, description, price;
@override
State<Details> createState() => _DetailsState();
}
class _DetailsState extends State<Details> {
int amount = 0;
DetailsModel? details;
Future<void> getData() async {
final result = await API().getDetails(widget.id);
if (mounted) {
setState(() {
details = result;
});
}
}
late String currentLanguage;
@override
void initState() {
getData();
currentLanguage = SettingsModel.of(context).currentLanguage;
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppTheme.lightBackgroundColor,
appBar: SapalyAppBar(
hasActionButton: true,
badge: '2',
title: widget.description,
actionButton: SvgPicture.asset('assets/icons/cart.svg'),
leadingButton: const Icon(Icons.arrow_back, color: AppTheme.blackColor),
leadingOnTap: () {
Navigator.of(context).pop();
},
actionOnTap: () {},
),
body: details == null
? const Center(child: CircularProgressIndicator())
: Container(
alignment: Alignment.center,
margin: EdgeInsets.symmetric(
horizontal: 20.adaptedPx(),
),
child: ScrollConfiguration(
behavior: CustomScrollBehavior(),
child: ListView(
// crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.symmetric(vertical: 15.adaptedPx()),
child: GestureDetector(
onTap: () {
PageNavigator(ctx: context)
.nextPage(page: PhotoScreen(widget.image));
},
child: ClipRRect(
clipBehavior: Clip.hardEdge,
borderRadius: BorderRadius.circular(16.adaptedPx()),
child: CachedNetworkImage(
imageUrl: widget.image,
width: double.infinity,
progressIndicatorBuilder:
(context, url, progress) => const Center(
child: CircularProgressIndicator(
color: AppTheme.lightPrimaryColor,
),
),
errorWidget: (context, url, error) => Container(
height: GlobalVariables.deviceHeight(context) / 7,
),
),
),
),
),
Align(
alignment: Alignment.centerLeft,
child: Text(
widget.description,
style: Theme.of(context)
.primaryTextTheme
.bodyMedium
?.copyWith(
fontWeight: FontWeight.w600,
fontSize: 18.adaptedPx(),
color: AppTheme.blackColor,
),
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 10.adaptedPx()),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
widget.description,
textAlign: TextAlign.left,
style: Theme.of(context)
.primaryTextTheme
.bodyMedium
?.copyWith(
fontWeight: FontWeight.w500,
fontSize: 13.adaptedPx(),
color: AppTheme.blackColor,
),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
widget.price,
style: Theme.of(context)
.primaryTextTheme
.bodyMedium
?.copyWith(
fontWeight: FontWeight.w600,
fontSize: 18.adaptedPx(),
color: AppTheme.blackColor,
),
),
const Spacer(),
Container(
decoration: BoxDecoration(
color: AppTheme.whiteColor,
borderRadius: BorderRadius.circular(16.adaptedPx()),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () {
setState(() {
amount++;
});
},
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(16.adaptedPx()),
bottomLeft:
Radius.circular(16.adaptedPx()),
),
),
),
child: Text(
'+',
style: Theme.of(context)
.primaryTextTheme
.bodyMedium
?.copyWith(
fontSize: 18.adaptedPx(),
color: AppTheme.blackColor,
),
),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: 10.adaptedPx()),
child: Text(
amount.toString(),
style: Theme.of(context)
.primaryTextTheme
.bodyMedium
?.copyWith(
fontSize: 18.adaptedPx(),
color: AppTheme.blackColor,
),
),
),
TextButton(
onPressed: () {
setState(() {
amount == 0 ? amount : amount--;
});
},
style: TextButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(16.adaptedPx()),
bottomRight:
Radius.circular(16.adaptedPx()),
),
),
),
child: Text(
'-',
style: Theme.of(context)
.primaryTextTheme
.bodyMedium
?.copyWith(
fontSize: 18.adaptedPx(),
color: AppTheme.blackColor,
),
),
),
],
),
),
],
),
SizedBox(height: 20.adaptedPx()),
InkWell(
splashColor: AppTheme.lightPrimaryColor.withOpacity(0.2),
highlightColor:
AppTheme.lightPrimaryColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(15.adaptedPx()),
onTap: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: AppTheme.lightPrimaryColor,
content: Text(
'added_to_cart'.translation,
style: Theme.of(context)
.primaryTextTheme
.bodyMedium
?.copyWith(
fontSize: 15.adaptedPx(),
fontWeight: FontWeight.w600,
color: AppTheme.whiteColor,
),
),
),
);
},
child: Container(
decoration: BoxDecoration(
border: Border.all(
width: 1.adaptedPx(),
color: AppTheme.lightPrimaryColor,
),
borderRadius: BorderRadius.circular(15.adaptedPx()),
),
padding: EdgeInsets.symmetric(
vertical: 15.adaptedPx(),
horizontal: 15.adaptedPx(),
),
child: Text(
'add_to_cart'.translation,
textAlign: TextAlign.center,
style: Theme.of(context)
.primaryTextTheme
.bodyMedium
?.copyWith(
fontSize: 15.adaptedPx(),
fontWeight: FontWeight.w600,
color: AppTheme.lightPrimaryColor,
),
),
),
),
SizedBox(height: 15.adaptedPx()),
],
),
),
),
);
}
}