From a28660be2111f2800b186e09260d2da6237b94d8 Mon Sep 17 00:00:00 2001 From: priyanka Date: Tue, 16 Apr 2024 00:56:42 -0700 Subject: [PATCH] My Subscription UI and api integration done --- gsf/lib/modals/subscriptionDataModel.dart | 49 ++++ .../repository/services/blog_services.dart | 6 - .../services/subscriptionDataService.dart | 22 ++ gsf/lib/views/pages/blog/blog_main.dart | 42 ++-- gsf/lib/views/pages/feedback/feedback.dart | 5 +- gsf/lib/views/pages/sidebar.dart | 21 +- .../pages/subscription/my_subscription.dart | 238 ++++++++++++++++++ 7 files changed, 352 insertions(+), 31 deletions(-) create mode 100644 gsf/lib/modals/subscriptionDataModel.dart create mode 100644 gsf/lib/repository/services/subscriptionDataService.dart create mode 100644 gsf/lib/views/pages/subscription/my_subscription.dart diff --git a/gsf/lib/modals/subscriptionDataModel.dart b/gsf/lib/modals/subscriptionDataModel.dart new file mode 100644 index 0000000..a73ea40 --- /dev/null +++ b/gsf/lib/modals/subscriptionDataModel.dart @@ -0,0 +1,49 @@ +class SubscriptionDataModel { + bool? success; + String? message; + Result? result; + + SubscriptionDataModel({this.success, this.message, this.result}); + + SubscriptionDataModel.fromJson(Map json) { + success = json['success']; + message = json['message']; + result = + json['result'] != null ? new Result.fromJson(json['result']) : null; + } + + Map toJson() { + final Map data = new Map(); + data['success'] = this.success; + data['message'] = this.message; + if (this.result != null) { + data['result'] = this.result!.toJson(); + } + return data; + } +} + +class Result { + int? id; + String? utmSource; + String? startDate; + String? endDate; + + Result({this.id, this.utmSource, this.startDate, this.endDate}); + + Result.fromJson(Map json) { + id = json['id']; + utmSource = json['utm_source']; + startDate = json['start_date']; + endDate = json['end_date']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['utm_source'] = this.utmSource; + data['start_date'] = this.startDate; + data['end_date'] = this.endDate; + return data; + } +} diff --git a/gsf/lib/repository/services/blog_services.dart b/gsf/lib/repository/services/blog_services.dart index ca555b2..5607865 100644 --- a/gsf/lib/repository/services/blog_services.dart +++ b/gsf/lib/repository/services/blog_services.dart @@ -1,10 +1,4 @@ import 'dart:async'; -import 'dart:convert'; - -import 'package:get/get.dart'; -import 'package:gsp_app/repository/endpoints.dart'; -import 'package:http/http.dart' as http; -import 'package:rxdart/rxdart.dart'; import '../../api/base_manager.dart'; import '../../api/network_api.dart'; diff --git a/gsf/lib/repository/services/subscriptionDataService.dart b/gsf/lib/repository/services/subscriptionDataService.dart new file mode 100644 index 0000000..f3ebcb9 --- /dev/null +++ b/gsf/lib/repository/services/subscriptionDataService.dart @@ -0,0 +1,22 @@ + +import '../../api/ResponseManager.dart'; +import '../../api/network_api.dart'; +import '../../modals/subscriptionDataModel.dart'; + +SubscriptionDataModel? subscriptionObj; + +class SubscriptionDataService { + Future> fetchSubscriptionData() async { + final response = await NetworkApi() + .getApi('https://gsf.betadelivery.com/api/userSubscriptionData'); + + if (response.data['success'] == true) { + subscriptionObj = SubscriptionDataModel.fromJson(response.data); + return ResponseData( + response.data['message'], ResponseStatus.SUCCESS); + } else { + return ResponseData( + response.data['message'], ResponseStatus.FAILED); + } + } +} diff --git a/gsf/lib/views/pages/blog/blog_main.dart b/gsf/lib/views/pages/blog/blog_main.dart index d893e30..50dcd0f 100644 --- a/gsf/lib/views/pages/blog/blog_main.dart +++ b/gsf/lib/views/pages/blog/blog_main.dart @@ -33,10 +33,6 @@ class _BlogMainState extends State with TickerProviderStateMixin { // final CategoryViewModel categoryViewModel = Get.put(CategoryViewModel()); StreamController blogsController = StreamController(); - - - - @override Widget build(BuildContext context) { return Scaffold( @@ -308,15 +304,21 @@ class _NewsBodyState extends State { physics: ScrollPhysics(), shrinkWrap: true, itemBuilder: (context, index) { - var updatedAtTime = searchArticle! - .result![index].updatedAt; - DateTime updatedAt = - DateTime.parse(updatedAtTime!); - Duration difference = - DateTime.now().difference(updatedAt); - String formattedDifference = DateFormat() - .add_Hm() - .format(updatedAt); + String formatDateTime( + String dateTimeString) { + // Parse the datetime string + DateTime dateTime = + DateTime.parse(dateTimeString); + + String formattedDateTime = + DateFormat('MMM dd, yyyy hh:mm a') + .format(dateTime); + + formattedDateTime += ' IST'; + + return formattedDateTime; + } + return cardList( articleName: searchArticle! .result![index].articleName ?? @@ -324,7 +326,10 @@ class _NewsBodyState extends State { thumbnailimg: searchArticle! .result![index].thumbnailPath ?? '', - updatedTime: formattedDifference, + updatedTime: formatDateTime( + searchArticle! + .result![index].updatedAt ?? + ''), categoryId: searchArticle!.result![index].id ?? 0, @@ -335,7 +340,10 @@ class _NewsBodyState extends State { searchArticle!.result![index].tags, InnerDescription: searchArticle! .result![index].description, - Innerformattedtime: formattedDifference, + Innerformattedtime: formatDateTime( + searchArticle! + .result![index].updatedAt ?? + ''), // articleid: widget.category.articles![index], ); })) @@ -496,7 +504,9 @@ cardList({ color: const Color(0xff707070), ), ), - child: Image.network(thumbnailimg, fit: BoxFit.fill), + child: ClipRRect( + borderRadius: BorderRadius.circular(100), + child: Image.network(thumbnailimg, fit: BoxFit.cover)), // Image.asset( // 'assets/image/avatar.png', diff --git a/gsf/lib/views/pages/feedback/feedback.dart b/gsf/lib/views/pages/feedback/feedback.dart index 56fb52f..b57c23f 100644 --- a/gsf/lib/views/pages/feedback/feedback.dart +++ b/gsf/lib/views/pages/feedback/feedback.dart @@ -83,6 +83,7 @@ class _FeedBackState extends State { } final isValid = _formkey.currentState?.validate(); if (isValid!) { + FocusScope.of(context).unfocus(); Map updata = { "user_id": '', "message": _textarea.text, @@ -282,8 +283,8 @@ class _FeedBackState extends State { // const Spacer(), InkWell( onTap: () async { - FocusScope.of(context).unfocus(); - _feedbackbutton(); + // FocusScope.of(context).unfocus(); + await _feedbackbutton(); }, child: Container( width: Get.width * 0.3, diff --git a/gsf/lib/views/pages/sidebar.dart b/gsf/lib/views/pages/sidebar.dart index 2a3e02a..3ec0ebf 100644 --- a/gsf/lib/views/pages/sidebar.dart +++ b/gsf/lib/views/pages/sidebar.dart @@ -15,6 +15,7 @@ import 'package:gsp_app/views/pages/profile/pages/profile_page.dart'; import 'package:gsp_app/views/pages/quiz/quiz_home.dart'; import 'package:gsp_app/views/pages/signIn/complete_profile_before_sign_in.dart'; import 'package:gsp_app/views/pages/signIn/sign_in.dart'; +import 'package:gsp_app/views/pages/subscription/my_subscription.dart'; import 'package:url_launcher/url_launcher.dart'; import '../../view_model/global_controller.dart'; import '../../view_model/home_controller.dart'; @@ -194,13 +195,12 @@ class _AppDrawerState extends State { false), const SizedBox(height: 15), menuWidget( - 'news_articles', - 'News & Articles', - () => Get.to( - () => const BlogMain(), - ), - false - ), + 'news_articles', + 'News & Articles', + () => Get.to( + () => const BlogMain(), + ), + false), const SizedBox(height: 15), // menuWidget( // 'instagram', @@ -275,6 +275,13 @@ class _AppDrawerState extends State { () => const ContactUs(), ); }, false), + const SizedBox(height: 15), + menuWidget('phone', 'My Subscription', () { + Get.back(); + Get.to( + () => const MySubscription(), + ); + }, false), // const SizedBox(height: 15), // menuWidget('phone', 'Test', () { Get.back(); diff --git a/gsf/lib/views/pages/subscription/my_subscription.dart b/gsf/lib/views/pages/subscription/my_subscription.dart new file mode 100644 index 0000000..f5b7b9c --- /dev/null +++ b/gsf/lib/views/pages/subscription/my_subscription.dart @@ -0,0 +1,238 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter/src/widgets/placeholder.dart'; +import 'package:get/get.dart'; +import 'package:intl/intl.dart'; + +import '../../../repository/services/subscriptionDataService.dart'; +import '../../../view_model/global_controller.dart'; +import '../../components/appbar.dart'; +import '../../theme.dart'; + +class MySubscription extends StatefulWidget { + const MySubscription({super.key}); + + @override + State createState() => _MySubscriptionState(); +} + +class _MySubscriptionState extends State { + late Future myfuture; + String? startDate; + String? enddate; + @override + void initState() { + myfuture = SubscriptionDataService().fetchSubscriptionData(); + + super.initState(); + } + + GlobalController globalController = Get.find(); + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: PreferredSize( + preferredSize: const Size.fromHeight(60), + child: CustomAppBars(titleHead: 'Subscription plan'), + ), + body: FutureBuilder( + future: myfuture, + builder: (context, snapshot) { + if (snapshot.data == null) { + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [CircularProgressIndicator()], + ), + ); + } + if (snapshot.connectionState == ConnectionState.done) { + if (snapshot.hasError) { + return Center( + child: Text( + '${snapshot.error} occured', + style: TextStyle(fontSize: 18), + ), + ); + } + } + startDate = subscriptionObj!.result!.startDate; + String formattedStartDate = + DateFormat('dd/MM/yyyy').format(DateTime.parse(startDate!)); + enddate = subscriptionObj!.result!.endDate; + String formattedEndDate = + DateFormat('dd/MM/yyyy').format(DateTime.parse(enddate!)); + return SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Column( + children: [ + SizedBox( + height: 60, + ), + Container( + // height: 400, + width: double.infinity, + decoration: BoxDecoration( + color: !globalController.darkMode.value + ? ColorConstants.kWhite + : const Color(0xff212121), + boxShadow: [ + BoxShadow( + spreadRadius: 2, + blurRadius: 10, + color: !globalController.darkMode.value + ? ColorConstants.kBlack.withOpacity(0.3) + : ColorConstants.kWhite.withOpacity(0), + ) + ], + borderRadius: BorderRadius.circular(30), + ), + child: Padding( + padding: const EdgeInsets.all(20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + subscriptionObj!.result!.utmSource ?? '', + style: TextStyle( + fontSize: 25, + color: !globalController.darkMode.value + ? ColorConstants.kBlack + : ColorConstants.kWhite, + fontFamily: 'SFPRO', + ), + ), + SizedBox( + height: 30, + ), + rowTile( + text: + 'Unlimited access to live virtual fitness classes led by certified trainers.'), + SizedBox( + height: 20, + ), + rowTile( + text: + 'Access to a library of workout videos covering various fitness levels and goals.'), + SizedBox( + height: 20, + ), + rowTile( + text: + 'Progress tracking to monitor your achievements and stay motivated.'), + SizedBox( + height: 20, + ), + rowTile( + text: + 'Basic nutrition guidance and meal planning tips.'), + SizedBox( + height: 20, + ), + ], + ), + ), + ), + SizedBox( + height: 25, + ), + Container( + // height: 40, + width: double.infinity, + decoration: BoxDecoration( + color: !globalController.darkMode.value + ? ColorConstants.kWhite + : const Color(0xff212121), + boxShadow: [ + BoxShadow( + spreadRadius: 2, + blurRadius: 10, + color: !globalController.darkMode.value + ? ColorConstants.kBlack.withOpacity(0.3) + : ColorConstants.kWhite.withOpacity(0), + ) + ], + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.fromLTRB(20, 16, 20, 16), + child: Center( + child: Row( + children: [ + Icon( + Icons.calendar_month_outlined, + color: Color(0xFFBBF046), + ), + SizedBox( + width: 10, + ), + Expanded( + child: Text( + // 'Membership till : 15/04/2024 - 15/10/2024', + 'Membership till : $formattedStartDate - $formattedEndDate', + + style: TextStyle( + fontSize: 14, + height: 2.2, + color: !globalController.darkMode.value + ? ColorConstants.kBlack + : ColorConstants.kWhite, + fontFamily: 'SFPRO', + ), + ), + ), + ], + ), + ), + )), + ], + ), + )); + }), + ); + } + + Widget rowTile({required String text}) { + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Column( + children: [ + SizedBox( + height: 10, + ), + Container( + height: 20, + width: 20, + decoration: BoxDecoration( + shape: BoxShape.circle, color: Color(0xffBBF046)), + child: Icon( + Icons.check, + size: 15, + color: Color(0xFF000000), + ), + ), + ], + ), + SizedBox( + width: 10, + ), + Expanded( + child: Text( + text, + style: TextStyle( + fontSize: 14, + height: 2.2, + color: !globalController.darkMode.value + ? ColorConstants.kBlack + : ColorConstants.kWhite, + fontFamily: 'SFPRO', + ), + ), + ), + ], + ); + } +}