From 068382e76f6325698f0639dd40cccf67068b5734 Mon Sep 17 00:00:00 2001 From: enadhilal Date: Sun, 18 Oct 2020 10:30:05 +0300 Subject: [PATCH] add call for backend service --- lib/config/config.dart | 5 + lib/core/service/client/base_app_client.dart | 30 +++ lib/pages/landing/home_page.dart | 4 + lib/pages/pharmacies/wishlist.dart | 246 ++++++++++++++++++ .../pharmacy_services/wishList_service.dart | 39 +++ lib/widgets/others/app_scaffold_widget.dart | 93 ++++--- pubspec.yaml | 2 +- 7 files changed, 379 insertions(+), 40 deletions(-) diff --git a/lib/config/config.dart b/lib/config/config.dart index 02b58b34..70c0d2fa 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -264,6 +264,11 @@ const GET_ALL_CITIES = 'services/Lists.svc/rest/GetAllCities'; const CREATE_E_REFERRAL = "Services/Patients.svc/REST/CreateEReferral"; const GET_E_REFERRALS = "Services/Patients.svc/REST/GetEReferrals"; + +//Pharmacy wishlist +const GET_WISHLIST = "http://swd-pharapp-01:7200/api/shopping_cart_items/"; + + const TIMER_MIN = 10; class AppGlobal { diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index f5494049..5bb50b0a 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -133,6 +133,36 @@ class BaseAppClient { } } + + get( + String endPoint, { + Function(dynamic response, int statusCode) onSuccess, + Function(String error, int statusCode) onFailure, + }) async { + try { + print("URL : $endPoint"); + + if (await Utils.checkConnection()) { + onFailure('Please Check The Internet Connection', -1); + } else { + final response = await http.get(endPoint, headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json' + }); + final int statusCode = response.statusCode; + if (statusCode < 200 || statusCode >= 400 || json == null) { + onFailure('Error While Fetching data', statusCode); + } else { + var parsed = json.decode(response.body.toString()); + onSuccess(parsed, statusCode); + } + } + } catch (e) { + print(e); + onFailure(e.toString(), -1); + } + } + logout() async { await sharedPref.remove(LOGIN_TOKEN_ID); Navigator.of(AppGlobal.context).pushReplacementNamed(LOGIN_TYPE); diff --git a/lib/pages/landing/home_page.dart b/lib/pages/landing/home_page.dart index 59c0a167..e12a0b95 100644 --- a/lib/pages/landing/home_page.dart +++ b/lib/pages/landing/home_page.dart @@ -7,6 +7,7 @@ import 'package:diplomaticquarterapp/pages/ErService/ErOptions.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/feedback/feedback_home_page.dart'; import 'package:diplomaticquarterapp/pages/paymentService/payment_service.dart'; +import 'package:diplomaticquarterapp/pages/pharmacies/wishlist.dart'; import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/pages/livecare/livecare_home.dart'; @@ -409,6 +410,9 @@ class _HomePageState extends State { ), height: MediaQuery.of(context).size.width * 0.4, imageName: 'al-habib_onlne_pharmacy_bg.png', + onTap: (){ + Navigator.push(context, FadePage(page: WishlistPage())); + }, ), DashboardItem( child: Center( diff --git a/lib/pages/pharmacies/wishlist.dart b/lib/pages/pharmacies/wishlist.dart index e69de29b..e9b3e9e1 100644 --- a/lib/pages/pharmacies/wishlist.dart +++ b/lib/pages/pharmacies/wishlist.dart @@ -0,0 +1,246 @@ +import 'package:diplomaticquarterapp/config/config.dart'; +import 'package:flutter/material.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:rating_bar/rating_bar.dart'; +import 'package:diplomaticquarterapp/services/pharmacy_services/wishList_service.dart'; + + +void main() => runApp(WishlistPage()); + +class WishlistPage extends StatefulWidget { + + @override + _WishlistPageState createState() => _WishlistPageState(); +} + +class _WishlistPageState extends State { + + @override + void initState(){ + WidgetsBinding.instance.addPostFrameCallback((_) => getWishListItems()); + } + + Widget build(BuildContext context) { + return AppScaffold( + appBarTitle: 'Wishlist page', + isShowAppBar: true, + isPharmacy: true, + body: Container( +// child: productTile(), + child: ListView.builder( + itemCount: 3, + itemBuilder: (BuildContext context, int index) { + return Column( + children: [ + Container( + child: productTile(), + ), + Divider(height: 1, color: Colors.grey) + ], + ); + }), + ), + ); + } +} + +getWishListItems() { + + print("getWishListItems"); + WishListService service = new WishListService(); + service.getWishlist(AppGlobal.context).then((res) { + print(res); + }); + +} + +productTile() { + return Container( + height: 120, + width: double.infinity, + color: Colors.white, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Row( + children: [ + Container( + margin: EdgeInsets.only(left: 10), + child: Image( + image: + AssetImage('assets/images/al-habib_onlne_pharmacy_bg.png'), + fit: BoxFit.cover, + width: 80, + height: 80, + ), + ), + Expanded( + flex: 5, + child: Column( + children: [ + Container( + margin: EdgeInsets.all(5), + child: Align( + alignment: Alignment.topLeft, + child: RichText( + text: TextSpan( + text: + 'Dulcolax 5 Mg 30 Tablets asdfasdfadsf asdfasdfas dasd fasdf asd fasdfsad', + style: TextStyle( + color: Colors.black54, + fontSize: 15, + fontWeight: FontWeight.bold), + ), + ), + ), + ), + Container( + margin: EdgeInsets.all(5), + child: Align( + alignment: Alignment.topLeft, + child: RichText( + text: TextSpan( + text: 'SAR 9999.99', + style: TextStyle( + fontWeight: FontWeight.bold, + color: Colors.black, + fontSize: 13), + ), + ), + ), + ), + Container( + margin: EdgeInsets.all(5), + child: Align( + alignment: Alignment.topLeft, + child: RatingBar.readOnly( + initialRating: 3, + size: 15.0, + filledColor: Colors.yellow[700], + emptyColor: Colors.grey[500], + isHalfAllowed: true, + halfFilledIcon: Icons.star_half, + filledIcon: Icons.star, + emptyIcon: Icons.star, + ), + ), + ), + ], + ), + ), + Expanded( + flex: 1, + child: Column( + children: [ + Icon(FontAwesomeIcons.trashAlt, size: 15), + SizedBox(height: 50,), + Icon(FontAwesomeIcons.shoppingCart, size: 15), + ], + ), + ), + ], + ), + ], + ), + ); +} + +//return Container( +//height: 120, +//color: Colors.white, +//child: Row( +//children: [ +//Container( +//margin: EdgeInsets.all(10), +//child: Image( +//image: AssetImage('assets/images/al-habib_onlne_pharmacy_bg.png'), +//fit: BoxFit.cover, +//), +//), +//Column( +//mainAxisAlignment: MainAxisAlignment.center, +//crossAxisAlignment: CrossAxisAlignment.start, +//children: [ +//Container( +//margin: EdgeInsets.all(5), +//child: Align( +//alignment: Alignment.topLeft, +//child: RichText( +//text: TextSpan( +//text: 'Dulcolax 5 Mg 30 Tablets', +//style: TextStyle( +//color: Colors.black54, +//fontSize: 15, +//fontWeight: FontWeight.bold), +//), +//), +//), +//), +//SizedBox(height: 10,), +//Container( +//margin: EdgeInsets.all(5), +//child: Align( +//alignment: Alignment.topLeft, +//child: RichText( +//text: TextSpan( +//text: 'SAR 9999.99', +//style: TextStyle( +//fontWeight: FontWeight.bold, +//color: Colors.black, +//fontSize: 13), +//), +//), +//), +//), +//SizedBox(height: 5,), +//Container( +//margin: EdgeInsets.only( +//right: MediaQuery.of(AppGlobal.context).size.width * 0.20), +//child: RatingBar.readOnly( +//initialRating: 3, +//// widget.doctor.actualDoctorRate.toDouble(), +//size: 15.0, +//filledColor: Colors.yellow[700], +//emptyColor: Colors.grey[500], +//isHalfAllowed: true, +//halfFilledIcon: Icons.star_half, +//filledIcon: Icons.star, +//emptyIcon: Icons.star, +//), +//), +//], +//), +//SizedBox(width: MediaQuery.of(AppGlobal.context).size.width *0.18,), +//// SizedBox(width: MediaQuery.of(AppGlobal.context).size.width *0.52,), +//Container( +//margin: EdgeInsets.only(top: 20), +//child: Column( +//children: [ +//Padding( +//padding: const EdgeInsets.only(left: 15.0), +//child: Align( +//alignment: Alignment.centerLeft, +//child: Icon(FontAwesomeIcons.trashAlt, size: 15), +//), +//), +//SizedBox( +//height: 50, +//), +//Padding( +//padding: const EdgeInsets.only(left: 10.0), +//child: Align( +//alignment: Alignment.centerLeft, +//child: Icon(FontAwesomeIcons.shoppingCart, size: 15), +//), +//), +//], +//), +//), +//], +//), +// +// +// +//); diff --git a/lib/services/pharmacy_services/wishList_service.dart b/lib/services/pharmacy_services/wishList_service.dart index e69de29b..0f9687e8 100644 --- a/lib/services/pharmacy_services/wishList_service.dart +++ b/lib/services/pharmacy_services/wishList_service.dart @@ -0,0 +1,39 @@ + +import 'package:diplomaticquarterapp/config/config.dart'; +import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; +import 'package:diplomaticquarterapp/core/service/base_service.dart'; +import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; +import 'package:diplomaticquarterapp/services/authentication/auth_provider.dart'; +import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; +import 'package:flutter/material.dart'; + + +class WishListService extends BaseService { + AppSharedPreferences sharedPref = AppSharedPreferences(); + AppGlobal appGlobal = new AppGlobal(); + + AuthenticatedUser authUser = new AuthenticatedUser(); + AuthProvider authProvider = new AuthProvider(); + + + Future getWishlist(BuildContext context) async { + + if (await this.sharedPref.getObject(USER_PROFILE) != null) { + var data = AuthenticatedUser.fromJson( + await this.sharedPref.getObject(USER_PROFILE)); + authUser = data; + } + + dynamic localRes; + String URL; + URL = GET_WISHLIST+"272843"+"?shopping_cart_type=2"; + await baseAppClient.get(URL, + onSuccess: (response, statusCode) async { + localRes = response; + }, onFailure: (String error, int statusCode) { + throw error; + }); + return Future.value(localRes); + } + +} diff --git a/lib/widgets/others/app_scaffold_widget.dart b/lib/widgets/others/app_scaffold_widget.dart index 80a3e7af..839f815b 100644 --- a/lib/widgets/others/app_scaffold_widget.dart +++ b/lib/widgets/others/app_scaffold_widget.dart @@ -26,6 +26,7 @@ class AppScaffold extends StatelessWidget { final bool hasAppBarParam; final BaseViewModel baseViewModel; final Widget floatingActionButton; + final bool isPharmacy; AppScaffold( {@required this.body, @@ -34,50 +35,64 @@ class AppScaffold extends StatelessWidget { this.isShowAppBar = false, this.hasAppBarParam, this.bottomSheet, - this.baseViewModel, this.floatingActionButton}); + this.baseViewModel, + this.floatingActionButton, + this.isPharmacy = false}); @override Widget build(BuildContext context) { AppGlobal.context = context; return Scaffold( - backgroundColor: Theme.of(context).scaffoldBackgroundColor, - appBar: isShowAppBar - ? AppBar( - elevation: 0, - backgroundColor: Theme.of(context).appBarTheme.color, - textTheme: TextTheme( - headline6: TextStyle( - color: Colors.white, fontWeight: FontWeight.bold), - ), - title: Text(appBarTitle.toUpperCase()), - leading: Builder( - builder: (BuildContext context) { - return ArrowBack(); - }, - ), - centerTitle: true, - actions: [ - IconButton( - icon: Icon(FontAwesomeIcons.home), - color: Colors.white, - onPressed: () { - Navigator.of(context).popUntil(ModalRoute.withName('/')); - }, - ), - ], - ) - : null, - body: baseViewModel != null - ? NetworkBaseView( - child: buildBodyWidget(), - baseViewModel: baseViewModel, - ) - : buildBodyWidget(), - bottomSheet: bottomSheet, - // bottomNavigationBar: BottomBarSearch() - floatingActionButton: floatingActionButton??floatingActionButton, - ); + backgroundColor: Theme.of(context).scaffoldBackgroundColor, + appBar: isShowAppBar + ? AppBar( + elevation: 0, + backgroundColor: isPharmacy + ? Colors.green + : Theme.of(context).appBarTheme.color, + textTheme: TextTheme( + headline6: + TextStyle(color: Colors.white, fontWeight: FontWeight.bold), + ), + title: Text(appBarTitle.toUpperCase()), + leading: Builder( + builder: (BuildContext context) { + return ArrowBack(); + }, + ), + centerTitle: true, + actions: [ + isPharmacy + ? IconButton( + icon: Icon(Icons.shopping_cart), + color: Colors.white, + onPressed: () { + Navigator.of(context) + .popUntil(ModalRoute.withName('/')); + }, + ) + : IconButton( + icon: Icon(FontAwesomeIcons.home), + color: Colors.white, + onPressed: () { + Navigator.of(context) + .popUntil(ModalRoute.withName('/')); + }, + ), + ], + ) + : null, + body: baseViewModel != null + ? NetworkBaseView( + child: buildBodyWidget(), + baseViewModel: baseViewModel, + ) + : buildBodyWidget(), + bottomSheet: bottomSheet, + // bottomNavigationBar: BottomBarSearch() + floatingActionButton: floatingActionButton ?? floatingActionButton, + ); } buildAppLoaderWidget(bool isLoading) { @@ -85,6 +100,6 @@ class AppScaffold extends StatelessWidget { } buildBodyWidget() { - return body ;//Stack(children: [body, buildAppLoaderWidget(isLoading)]); + return body; //Stack(children: [body, buildAppLoaderWidget(isLoading)]); } } diff --git a/pubspec.yaml b/pubspec.yaml index 8bc2c52a..e72fc846 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -82,7 +82,7 @@ dependencies: table_calendar: ^2.2.3 # SVG Images - flutter_svg: ^0.18.0 + flutter_svg: any # Location Helper map_launcher: ^0.8.1