Skip to content

Commit

Permalink
Can delete, add Category now
Browse files Browse the repository at this point in the history
  • Loading branch information
xMadKing committed Dec 27, 2023
1 parent c8413f9 commit d500deb
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 36 deletions.
98 changes: 70 additions & 28 deletions lib/pages/addnewbudget.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:smartspend/backend/category.dart';
import 'package:smartspend/backend/wyrm/database.dart';
import 'package:smartspend/widgets/backbutton.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'package:smartspend/widgets/savenewcat.dart';
Expand All @@ -13,12 +15,21 @@ class AddNewCat extends StatefulWidget {
}

class _AddNewCat extends State<AddNewCat> {
Color selectedColor = Color(0xff3B9A2C);
FocusNode _textFieldFocusNode = FocusNode();
TextEditingController _catNameController = TextEditingController();
TextEditingController _amountController = TextEditingController();
TextEditingController _descController = TextEditingController();

bool _isKeyboardAppear = false;
bool categoryAdded = false;

void setColor(Color newColor){
setState(() {
selectedColor = newColor;
});
print(newColor);
}

@override
void initState() {
Expand Down Expand Up @@ -61,12 +72,7 @@ class _AddNewCat extends State<AddNewCat> {
fontWeight: FontWeight.w600
)),
SizedBox(height: 70),
Text('Total Available Budget', style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12,
color: Colors.white,
)),
Text('FROM USER DATA', style: TextStyle( //should be the number of money available in the account
Text('Add a category', style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 30,
height: 1.2,
Expand Down Expand Up @@ -174,6 +180,7 @@ class _AddNewCat extends State<AddNewCat> {
child: TextField(
controller: _amountController,
focusNode: _textFieldFocusNode,
keyboardType: TextInputType.number,
style: TextStyle(
fontFamily: 'Montserrat',
fontWeight: FontWeight.w600,
Expand Down Expand Up @@ -201,7 +208,8 @@ class _AddNewCat extends State<AddNewCat> {
),
ColorSelect(
desiredH: desiredHeight,
desiredW: desiredWidth
desiredW: desiredWidth,
updateColor: setColor,
),
]
),
Expand Down Expand Up @@ -248,26 +256,53 @@ class _AddNewCat extends State<AddNewCat> {
)
]
),
Container(
padding: const EdgeInsets.only(top: 20),
alignment: Alignment.center,
child: NewCatButton(
onPressed: () {
// Handle button press
// The text here is to be added to the database
print(_catNameController.text);
print(_amountController.text);
print(_descController.text);
// Navigate to Manage Budget page
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => MainBudget())
);
},
),
),

]
Visibility(
visible: categoryAdded,
child: Center(
child: Container(
padding: const EdgeInsets.only(top: 20),
child: Icon(
Icons.check_circle_rounded,
color: Colors.green,
size: 50,
),
)
),
),
Visibility(
visible: !categoryAdded,
child: Container(
padding: const EdgeInsets.only(top: 20),
alignment: Alignment.center,
child: NewCatButton(
onPressed: () async {
// Handle button press
// The text here is to be added to the database
Category newCategory = Category(
categoryColor: selectedColor.value,
categoryID: DateTime.now().millisecondsSinceEpoch,
categoryName: _catNameController.text,
spendingLimit: int.parse(_amountController.text),
userID: 1,
);
Wyrm database = Wyrm();
database.insertToTable(newCategory, 'category');
setState(() {
_amountController.text = "";
_catNameController.text = "";
_catNameController.text = "";
_descController.text = "";
categoryAdded = true;
});
await Future.delayed(Duration(seconds: 1));
setState(() {
categoryAdded = false;
});
},
),
),
)
]
)
)
),
Expand All @@ -281,8 +316,14 @@ class _AddNewCat extends State<AddNewCat> {
class ColorSelect extends StatefulWidget{
final double desiredW;
final double desiredH;
final Function(Color) updateColor;

ColorSelect({super.key, required this.desiredH, required this.desiredW});
ColorSelect({
super.key,
required this.desiredH,
required this.desiredW,
required this.updateColor
});

@override
State<StatefulWidget> createState() => _ColorSelect();
Expand All @@ -300,6 +341,7 @@ class _ColorSelect extends State<ColorSelect>{
child: BlockPicker(
pickerColor: chosen,
onColorChanged: (color) {
widget.updateColor(color);
setState(() {
chosen = color;
});
Expand Down
9 changes: 4 additions & 5 deletions lib/pages/managebudget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ class MainBudget extends StatefulWidget {

class _MainBudgetState extends State<MainBudget> {

//calculate available budget in acc
//double available = ;

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -43,12 +40,12 @@ class _MainBudgetState extends State<MainBudget> {
fontWeight: FontWeight.w800
)),
SizedBox(height: 70),
Text('Total Available Budget', style: TextStyle(
Text('Slide category to delete', style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12,
color: Colors.white,
)),
Text("Available", style: TextStyle( //should be the number of money available in the account
Text("Your categories", style: TextStyle( //should be the number of money available in the account
fontFamily: 'Montserrat',
fontSize: 30,
height: 1.2,
Expand Down Expand Up @@ -114,6 +111,7 @@ class _LV extends State<LV> {
name: "No category founded", // Access the property of Category
color: Colors.red,
number: 0,
categoryID: -1,
);
}
return Column(
Expand All @@ -131,6 +129,7 @@ class _LV extends State<LV> {
name: categories[index].categoryName, // Access the property of Category
color: Color(categories[index].categoryColor),
number: categories[index].spendingLimit,
categoryID: categories[index].categoryID,
);
},
),
Expand Down
44 changes: 41 additions & 3 deletions lib/widgets/editablebudgetcat.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:smartspend/backend/wyrm/database.dart';

class EditableBudgetCat extends StatefulWidget{
final String name;
final Color color;
final num number;
final int categoryID;

const EditableBudgetCat({super.key, required this.name, required this.color, required this.number});
const EditableBudgetCat({super.key,
required this.name,
required this.color,
required this.number,
required this.categoryID});

@override
State<EditableBudgetCat> createState() => _EditableBudgetCat();
}

class _EditableBudgetCat extends State<EditableBudgetCat> {
//should access the database and instead of the list
bool deleted = false;

@override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height / 14;
double width = MediaQuery.of(context).size.width /1.2;

if(deleted){
return Container(
width: width,
height: height,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.red,
),
child: Center(
child: Text(
"DELETED",
style: TextStyle(
fontFamily: "Montserrat",
fontSize: 22,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
)
);
}

return Stack(
//crossAxisAlignment: CrossAxisAlignment.start,
//mainAxisAlignment: MainAxisAlignment.center,
Expand All @@ -42,7 +70,17 @@ class _EditableBudgetCat extends State<EditableBudgetCat> {
child: Align(
alignment: Alignment.centerRight,
child: InkWell(
onTap: () {},
onTap: () async {
Wyrm database = Wyrm();
await database.deleteFromTable(
"categoryID",
'category',
widget.categoryID
);
setState(() {
deleted = true;
});
},
child: Container(
alignment: Alignment.center,
width: 120,
Expand Down

0 comments on commit d500deb

Please sign in to comment.