2022-05-16 09:20:27 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-05-16 09:58:22 +02:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
2022-05-16 15:55:38 +02:00
|
|
|
|
|
|
|
import 'package:nekoya_flutter/api/api.dart';
|
2022-05-16 09:58:22 +02:00
|
|
|
import 'package:nekoya_flutter/utils/utils.dart';
|
2022-05-16 09:20:27 +02:00
|
|
|
|
|
|
|
const OutlineInputBorder outlineInputBorder = OutlineInputBorder(
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(12)),
|
|
|
|
borderSide: BorderSide.none,
|
|
|
|
);
|
|
|
|
|
2022-05-16 15:55:38 +02:00
|
|
|
class Newsletter extends StatefulWidget {
|
|
|
|
const Newsletter({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<Newsletter> createState() => _NewsletterState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _NewsletterState extends State<Newsletter> {
|
|
|
|
TextEditingController emailController = TextEditingController();
|
2022-05-16 09:20:27 +02:00
|
|
|
|
2022-05-16 15:30:32 +02:00
|
|
|
@override
|
2022-05-16 09:20:27 +02:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.only(top: 25.0, left: 10.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
2022-05-16 11:02:10 +02:00
|
|
|
const Text(
|
2022-05-16 09:20:27 +02:00
|
|
|
'Newsletter',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 20.0,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
2022-05-16 11:02:10 +02:00
|
|
|
const Text(
|
2022-05-16 09:20:27 +02:00
|
|
|
'Subscribe to Our Newsletter and get 20% off your first purchase',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 13.0,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 25.0),
|
|
|
|
child: TextFormField(
|
2022-05-16 15:55:38 +02:00
|
|
|
controller: emailController,
|
2022-05-16 11:02:10 +02:00
|
|
|
style: const TextStyle(color: Colors.white),
|
2022-05-16 09:20:27 +02:00
|
|
|
decoration: InputDecoration(
|
2022-05-16 09:58:22 +02:00
|
|
|
filled: true,
|
|
|
|
fillColor: const Color(0xff212226),
|
|
|
|
hintText: "Input Your Email",
|
|
|
|
hintStyle: const TextStyle(color: Colors.white),
|
|
|
|
border: outlineInputBorder,
|
|
|
|
enabledBorder: outlineInputBorder,
|
|
|
|
focusedBorder: outlineInputBorder,
|
|
|
|
errorBorder: outlineInputBorder,
|
|
|
|
prefixIcon: Padding(
|
|
|
|
padding: const EdgeInsets.all(14),
|
|
|
|
child: SvgPicture.asset(
|
|
|
|
"assets/icons/email.svg",
|
|
|
|
color: Colors.white,
|
|
|
|
width: 21.5,
|
|
|
|
height: 21.5,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
suffixIcon: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: defaultPadding,
|
|
|
|
vertical: defaultPadding / 2),
|
|
|
|
child: SizedBox(
|
|
|
|
width: 100,
|
|
|
|
height: 48,
|
|
|
|
child: ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary: const Color(0xff8B0000),
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.all(Radius.circular(12)),
|
|
|
|
)),
|
2022-05-16 15:55:38 +02:00
|
|
|
onPressed: () {
|
|
|
|
if (emailController.text.isNotEmpty) {
|
|
|
|
subscribe(emailController.text).then((status) {
|
2022-05-16 16:03:50 +02:00
|
|
|
emailController.clear();
|
2022-05-16 15:55:38 +02:00
|
|
|
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 <Widget>[
|
|
|
|
Text('You have successfully subscribed to the newsletter.', style: TextStyle(
|
|
|
|
color: Colors.white
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
child: const Text('Close', style: TextStyle(color: Colors.white),),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2022-05-16 09:58:22 +02:00
|
|
|
child: const Text(
|
|
|
|
'SUBSCRIBE',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12.0,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)),
|
2022-05-16 09:20:27 +02:00
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|