From 6393d1a053d1367bab03bf0968d5430dd44d6759 Mon Sep 17 00:00:00 2001 From: Moe Date: Mon, 16 May 2022 20:55:38 +0700 Subject: [PATCH] Update subscribe --- lib/api/api.dart | 5 ++++ lib/components/newsletter.dart | 54 ++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/lib/api/api.dart b/lib/api/api.dart index 3e39cba..edba009 100644 --- a/lib/api/api.dart +++ b/lib/api/api.dart @@ -83,3 +83,8 @@ Future checkoutPost(session, data) async { ); return req.statusCode; } + +Future subscribe(email) async { + var req = await Dio().get('$host/subscribe', queryParameters: {'email': email}); + return req.statusCode; +} \ No newline at end of file diff --git a/lib/components/newsletter.dart b/lib/components/newsletter.dart index 27a2ff3..b517927 100644 --- a/lib/components/newsletter.dart +++ b/lib/components/newsletter.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; + +import 'package:nekoya_flutter/api/api.dart'; import 'package:nekoya_flutter/utils/utils.dart'; const OutlineInputBorder outlineInputBorder = OutlineInputBorder( @@ -7,10 +9,15 @@ const OutlineInputBorder outlineInputBorder = OutlineInputBorder( borderSide: BorderSide.none, ); -class Newsletter extends StatelessWidget { - const Newsletter({ - Key? key, - }) : super(key: key); +class Newsletter extends StatefulWidget { + const Newsletter({Key? key}) : super(key: key); + + @override + State createState() => _NewsletterState(); +} + +class _NewsletterState extends State { + TextEditingController emailController = TextEditingController(); @override Widget build(BuildContext context) { @@ -40,6 +47,7 @@ class Newsletter extends StatelessWidget { Padding( padding: const EdgeInsets.only(top: 25.0), child: TextFormField( + controller: emailController, style: const TextStyle(color: Colors.white), decoration: InputDecoration( filled: true, @@ -73,7 +81,43 @@ class Newsletter extends StatelessWidget { borderRadius: BorderRadius.all(Radius.circular(12)), )), - onPressed: () {}, + onPressed: () { + if (emailController.text.isNotEmpty) { + subscribe(emailController.text).then((status) { + if (status == 200) { + return showDialog( + context: context, + barrierDismissible: false, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Thank You', style: TextStyle(color: Colors.white),), + backgroundColor: const Color(0xff212226), + content: SingleChildScrollView( + child: ListBody( + children: const [ + Text('You have successfully subscribed to the newsletter.', style: TextStyle( + color: Colors.white + )), + ], + ), + ), + actions: [ + TextButton( + child: const Text('Close', style: TextStyle(color: Colors.white),), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + } + ); + } else { + + } + }); + } + }, child: const Text( 'SUBSCRIBE', style: TextStyle(