mirror of
https://github.com/Shchoholiev/shopping-assistant-mobile-client.git
synced 2025-04-03 16:19:51 +00:00
Working cart screen, added call from wishlists screen.
This commit is contained in:
parent
56363cacc2
commit
6fd516e09b
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:graphql/client.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:shopping_assistant_mobile_client/models/product.dart';
|
||||
import 'package:shopping_assistant_mobile_client/network/api_client.dart';
|
||||
|
||||
@ -8,13 +9,16 @@ const String defaultUrl = 'https://s3-alpha-sig.figma.com/img/b8d6/7b6f/59839f0f
|
||||
|
||||
|
||||
class CartScreen extends StatefulWidget {
|
||||
const CartScreen({super.key});
|
||||
CartScreen({super.key, required this.wishlistId});
|
||||
|
||||
final String wishlistId;
|
||||
|
||||
@override
|
||||
State<CartScreen> createState() => _CartScreenState();
|
||||
State<CartScreen> createState() => _CartScreenState(wishlistId: wishlistId);
|
||||
}
|
||||
|
||||
class _CartScreenState extends State<CartScreen> {
|
||||
_CartScreenState({required this.wishlistId});
|
||||
// final _products = [
|
||||
// Product(name : '1', id: "Belkin USB C to VGA + Charge Adapter - USB C to VGA Cable for MacBook", price: 12.57, rating: 4.34, url: 'a', imageUrls: [defaultUrl,'a','b']),
|
||||
// Product(id : '1', name: "USB C to VGA 2", price: 12.57, rating: 4.5, url: 'a', imageUrls: [defaultUrl,'a','b']),
|
||||
@ -25,6 +29,8 @@ class _CartScreenState extends State<CartScreen> {
|
||||
|
||||
var client = ApiClient();
|
||||
|
||||
final String wishlistId;
|
||||
|
||||
late Future _productsFuture;
|
||||
late List<Product> _products;
|
||||
|
||||
@ -55,8 +61,8 @@ class _CartScreenState extends State<CartScreen> {
|
||||
|
||||
QueryOptions queryOptions = QueryOptions(
|
||||
document: gql(productsPageFromPersonalWishlistQuery),
|
||||
variables: const <String, dynamic>{
|
||||
'wishlistId': "657310c6892da98a23091bdf",
|
||||
variables: <String, dynamic>{
|
||||
'wishlistId': wishlistId,
|
||||
'pageNumber': 1,
|
||||
'pageSize': 10,
|
||||
});
|
||||
@ -92,17 +98,19 @@ class _CartScreenState extends State<CartScreen> {
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.arrow_back),
|
||||
onPressed: () {
|
||||
print('Back button pressed');
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
),
|
||||
body: ListView.builder(
|
||||
body: _products.length == 0 ?
|
||||
Center(child: Text("The cart is empty", style: TextStyle(fontSize: 18),),)
|
||||
: ListView.builder(
|
||||
padding: EdgeInsets.symmetric(vertical: 30),
|
||||
itemCount: _products.length,
|
||||
itemBuilder: (context, index){
|
||||
return CartItem(product: _products[index]);
|
||||
}
|
||||
),
|
||||
),
|
||||
backgroundColor: Colors.white,
|
||||
);
|
||||
};
|
||||
@ -112,28 +120,6 @@ class _CartScreenState extends State<CartScreen> {
|
||||
);
|
||||
}
|
||||
);
|
||||
// return Scaffold(
|
||||
// appBar: AppBar(
|
||||
// title: Text("Cart"),
|
||||
// centerTitle: true,
|
||||
// //titleTextStyle: TextStyle(color: Colors.black),
|
||||
// //backgroundColor: ,
|
||||
// leading: IconButton(
|
||||
// icon: Icon(Icons.arrow_back),
|
||||
// onPressed: () {
|
||||
// print('Back button pressed');
|
||||
// },
|
||||
// ),
|
||||
// ),
|
||||
// body: ListView.builder(
|
||||
// padding: EdgeInsets.symmetric(vertical: 30),
|
||||
// itemCount: _products.length,
|
||||
// itemBuilder: (context, index){
|
||||
// return CartItem(product: _products[index]);
|
||||
// }
|
||||
// ),
|
||||
// backgroundColor: Colors.white,
|
||||
// );
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,6 +157,12 @@ class CartItem extends StatelessWidget{
|
||||
return stars;
|
||||
}
|
||||
|
||||
|
||||
Future<void> _launchUrl(String url) async {
|
||||
final Uri uri = Uri.parse(url);
|
||||
if (!await launchUrl(uri)) throw 'Could not launch $url';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@ -225,7 +217,7 @@ class CartItem extends StatelessWidget{
|
||||
width: double.infinity,
|
||||
height: 35,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: ()=>{},
|
||||
onPressed: () => _launchUrl(_product.url),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blue,// Блакитний колір фону кнопки
|
||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
|
@ -3,6 +3,7 @@ import 'package:flutter_svg/svg.dart';
|
||||
import 'package:graphql/client.dart';
|
||||
import 'package:shopping_assistant_mobile_client/models/wishlist.dart';
|
||||
import 'package:shopping_assistant_mobile_client/network/api_client.dart';
|
||||
import 'package:shopping_assistant_mobile_client/screens/cart.dart';
|
||||
|
||||
class WishlistsScreen extends StatefulWidget {
|
||||
const WishlistsScreen({super.key});
|
||||
@ -258,7 +259,7 @@ class _WishlistItemState extends State<WishlistItem> {
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
Text('Cart ' + widget._wishlist.id)))),
|
||||
CartScreen(wishlistId: widget._wishlist.id)))),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
|
66
pubspec.lock
66
pubspec.lock
@ -541,6 +541,70 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.2"
|
||||
url_launcher:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: url_launcher
|
||||
sha256: e9aa5ea75c84cf46b3db4eea212523591211c3cf2e13099ee4ec147f54201c86
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.2.2"
|
||||
url_launcher_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_android
|
||||
sha256: "31222ffb0063171b526d3e569079cf1f8b294075ba323443fdc690842bfd4def"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.2.0"
|
||||
url_launcher_ios:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_ios
|
||||
sha256: bba3373219b7abb6b5e0d071b0fe66dfbe005d07517a68e38d4fc3638f35c6d3
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "6.2.1"
|
||||
url_launcher_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_linux
|
||||
sha256: "9f2d390e096fdbe1e6e6256f97851e51afc2d9c423d3432f1d6a02a8a9a8b9fd"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
url_launcher_macos:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_macos
|
||||
sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
url_launcher_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_platform_interface
|
||||
sha256: "980e8d9af422f477be6948bdfb68df8433be71f5743a188968b0c1b887807e50"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
url_launcher_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_web
|
||||
sha256: "7fd2f55fe86cea2897b963e864dc01a7eb0719ecc65fcef4c1cc3d686d718bb2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
url_launcher_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: url_launcher_windows
|
||||
sha256: "7754a1ad30ee896b265f8d14078b0513a4dba28d358eabb9d5f339886f4a1adc"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
uuid:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -631,4 +695,4 @@ packages:
|
||||
version: "3.1.2"
|
||||
sdks:
|
||||
dart: ">=3.1.4 <4.0.0"
|
||||
flutter: ">=3.7.0"
|
||||
flutter: ">=3.13.0"
|
||||
|
@ -32,6 +32,7 @@ dependencies:
|
||||
sdk: flutter
|
||||
flutter_spinkit: ^5.0.0
|
||||
logger: ^2.0.2+1
|
||||
url_launcher: ^6.0.12
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
|
Loading…
Reference in New Issue
Block a user