You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
293 lines
9.2 KiB
293 lines
9.2 KiB
import 'package:flutter/material.dart';
|
|
import 'dart:math' as math;
|
|
import 'PageWidgets/DesireComeTrue/DesiredItem.dart';
|
|
import 'package:teso/util/consts.dart';
|
|
import 'package:teso/Classes/API Clasess/Desire.dart';
|
|
import 'package:teso/providers/pageAnimations.dart';
|
|
import 'Sub_Pages/Desires Come True/AddDesire.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'dart:convert';
|
|
import 'package:jiffy/jiffy.dart';
|
|
|
|
class DesireComeTrue extends StatefulWidget {
|
|
@override
|
|
_DesireComeTrueState createState() => _DesireComeTrueState();
|
|
}
|
|
|
|
class _DesireComeTrueState extends State<DesireComeTrue>
|
|
with TickerProviderStateMixin {
|
|
AnimationController _controller;
|
|
Animation<double> _fabScale;
|
|
List<Desire> desires = <Desire>[];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = AnimationController(
|
|
vsync: this, duration: const Duration(milliseconds: 500));
|
|
|
|
_fabScale = Tween<double>(begin: 0, end: 1)
|
|
.animate(CurvedAnimation(parent: _controller, curve: Curves.bounceOut));
|
|
|
|
_fabScale.addListener(() {
|
|
setState(() {});
|
|
});
|
|
SharedPreferences.getInstance().then((value) {
|
|
var jiffy = Jiffy()..add(months: 1);
|
|
if (value.getString("desire" + jiffy.format("MMMM, yyyy")).isNotEmpty) {
|
|
var desired =
|
|
jsonDecode(value.getString("desire" + jiffy.format("MMMM, yyyy")));
|
|
setState(() {
|
|
desires = List<Desire>.from(
|
|
desired.map((model) => Desire.fromJSON(model)).toList());
|
|
});
|
|
print(desires.toString());
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> desiredList(context) async {
|
|
if (desires.length != 0)
|
|
try {
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
Map<String, String> requestHeaders = {
|
|
'Content-type': 'application/json',
|
|
'Authorization': prefs.getString('tokensTeso')
|
|
};
|
|
|
|
var register2 = serverLocation + 'monthly-desires/submit-newdesire';
|
|
var client1 = await http.post(Uri.parse(register2),
|
|
body: json.encode(desires), headers: requestHeaders);
|
|
|
|
if (client1.statusCode == 200) {
|
|
await tesoSuccessDialog(context);
|
|
Future.delayed(const Duration(seconds: 5), () {
|
|
Navigator.of(context).pop();
|
|
Navigator.of(context).pop();
|
|
});
|
|
} else {
|
|
await error(context);
|
|
}
|
|
} catch (e) {
|
|
await error(context);
|
|
}
|
|
}
|
|
|
|
error(context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext bc) {
|
|
return AlertDialog(
|
|
actions: <Widget>[
|
|
TextButton(
|
|
child: Text('OK'),
|
|
onPressed: () {
|
|
Navigator.of(context).pop();
|
|
},
|
|
),
|
|
],
|
|
//title: Text("Alert Dialog"),
|
|
content: Text(
|
|
"Sorry an error occurred please try again!",
|
|
style: TextStyle(color: Colors.redAccent[100]),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
tesoSuccessDialog(context) {
|
|
var jiffy = Jiffy()..add(months: 1);
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext bc) {
|
|
return AlertDialog(
|
|
title: Text(
|
|
"Success",
|
|
style: TextStyle(color: Colors.green[400]),
|
|
),
|
|
actions: <Widget>[
|
|
// TextButton(
|
|
// child: Text(
|
|
// 'OK',
|
|
// style: TextStyle(color: Colors.green[400]),
|
|
// ),
|
|
// onPressed: () {
|
|
// Navigator.of(context).pop(true);
|
|
// },
|
|
// ),
|
|
],
|
|
//title: Text("Alert Dialog"),
|
|
content: Text(
|
|
"Monthly Desire Come True List for " +
|
|
jiffy.format("MMMM, yyyy") +
|
|
" has been set successfully",
|
|
style: TextStyle(color: Colors.green[400]),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
automaticallyImplyLeading: true,
|
|
title: Text(
|
|
"Desires Come True",
|
|
style: TextStyle(
|
|
color: Theme.of(context).primaryColorLight,
|
|
fontFamily: 'DeadheadScript',
|
|
fontSize: 35,
|
|
letterSpacing: 3.0,
|
|
),
|
|
),
|
|
actions: [
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: Colors.green,
|
|
),
|
|
child: IconButton(
|
|
icon: Icon(
|
|
Icons.add,
|
|
color: Colors.white,
|
|
),
|
|
onPressed: () => Navigator.push(
|
|
context,
|
|
PageTransition(
|
|
type: PageTransitionType.fade,
|
|
child: NewDesire(
|
|
selected: desires,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
body: SingleChildScrollView(
|
|
scrollDirection: Axis.vertical,
|
|
physics: NeverScrollableScrollPhysics(),
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
padding: EdgeInsets.all(10),
|
|
width: double.infinity,
|
|
margin: EdgeInsets.only(
|
|
bottom: MediaQuery.of(context).size.height * 0.02,
|
|
top: MediaQuery.of(context).size.height * 0.02,
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
"Welcome to your monthly desires come true, here you can set up a list of items you would like to get discount or freebie coupons on " +
|
|
"for the month ahead...",
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
color: Colors.grey,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
padding: EdgeInsets.all(8),
|
|
child: Transform.rotate(
|
|
angle: math.pi / -45,
|
|
child: Card(
|
|
color: Colors.white,
|
|
elevation: 6,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(5)),
|
|
child: Column(
|
|
children: <Widget>[
|
|
Container(
|
|
color: Colors.white,
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: (MediaQuery.of(context).size.width / 3),
|
|
),
|
|
child: Text(
|
|
"Items",
|
|
style: TextStyle(
|
|
color: Colors.black87,
|
|
fontFamily: 'DeadheadScript',
|
|
fontSize: 40,
|
|
letterSpacing: 3.0,
|
|
),
|
|
),
|
|
),
|
|
_headSeparator(),
|
|
Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
height: MediaQuery.of(context).size.width - 10,
|
|
child: ListView.builder(
|
|
scrollDirection: Axis.vertical,
|
|
itemCount: desires.length,
|
|
itemBuilder: (context, index) {
|
|
if (desires.isNotEmpty) {
|
|
return Column(
|
|
children: [
|
|
DesiredItem(
|
|
item: desires.elementAt(index),
|
|
number: index + 1,
|
|
selected: desires,
|
|
),
|
|
_separator(),
|
|
],
|
|
);
|
|
} else {
|
|
return Container();
|
|
}
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
floatingActionButton: Container(
|
|
margin: EdgeInsets.only(
|
|
top: 10,
|
|
),
|
|
width: MediaQuery.of(context).size.width / 2,
|
|
height: 40,
|
|
decoration: new BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
//color: Colors.grey,
|
|
),
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(20.0),
|
|
),
|
|
),
|
|
primary: accentMain,
|
|
),
|
|
onPressed: () async => desiredList(context),
|
|
child: Text(
|
|
"Submit",
|
|
style: TextStyle(color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget _separator() {
|
|
return Container(
|
|
height: 1,
|
|
decoration: BoxDecoration(color: Colors.blue.withAlpha(100)),
|
|
);
|
|
}
|
|
|
|
Widget _headSeparator() {
|
|
return Container(
|
|
height: 3,
|
|
decoration: BoxDecoration(color: tesoGold),
|
|
);
|
|
}
|
|
|