Update mybutton widget to take in buttonColor & TextColour. Add Success message pop up message.

Update all buttons to include button color and text colors.
This commit is contained in:
2024-07-03 16:33:52 +02:00
parent b25583ddf3
commit 0c40888907
10 changed files with 226 additions and 88 deletions

View File

@@ -0,0 +1,98 @@
import 'package:flutter/material.dart';
import 'package:patient_manager/components/mybutton.dart';
class MySuccessMessage extends StatefulWidget {
final String successType;
final String successMessage;
const MySuccessMessage({
super.key,
required this.successType,
required this.successMessage,
});
@override
State<MySuccessMessage> createState() => _MySuccessMessageState();
}
class _MySuccessMessageState extends State<MySuccessMessage> {
var messageTypes = <String, Widget>{};
late String message;
void setSuccessmessage() {
messageTypes["Success"] = Stack(
children: [
Container(
padding: const EdgeInsets.all(10.0),
width: 500.0,
// height: 375.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25.0),
border: Border.all(color: Colors.green, width: 5.0),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.check_circle_outline_rounded,
size: 100,
color: Colors.green,
),
const SizedBox(height: 15),
const Text(
"Success!",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.green,
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Text(
message,
style: const TextStyle(
color: Colors.black,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 10),
SizedBox(
width: 300,
height: 100,
child: MyButton(
onTap: () {
Navigator.pop(context);
},
buttonText: "Dismiss",
buttonColor: Colors.green,
textColor: Colors.white,
),
),
],
),
),
],
);
}
Widget? getSuccessMessage(String type) {
return messageTypes[type];
}
@override
void initState() {
message = widget.successMessage;
setSuccessmessage();
super.initState();
}
@override
Widget build(BuildContext context) {
return Dialog(child: getSuccessMessage(widget.successType));
}
}

View File

@@ -3,8 +3,16 @@ import 'package:flutter/material.dart';
class MyButton extends StatelessWidget { class MyButton extends StatelessWidget {
final void Function() onTap; final void Function() onTap;
final String buttonText; final String buttonText;
final Color buttonColor;
final Color textColor;
const MyButton({super.key, required this.onTap, required this.buttonText}); const MyButton({
super.key,
required this.onTap,
required this.buttonText,
required this.buttonColor,
required this.textColor,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -13,17 +21,17 @@ class MyButton extends StatelessWidget {
child: ElevatedButton( child: ElevatedButton(
onPressed: onTap, onPressed: onTap,
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: Colors.blueAccent, backgroundColor: buttonColor,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0), borderRadius: BorderRadius.circular(12.0),
), ),
), ),
child: Text( child: Text(
buttonText, buttonText,
style: const TextStyle( style: TextStyle(
//fontWeight: FontWeight.bold, //fontWeight: FontWeight.bold,
fontSize: 20, fontSize: 20,
color: Colors.white, color: textColor,
), ),
), ),
), ),

View File

@@ -215,24 +215,28 @@ class _PatientFilesState extends State<PatientFiles> {
retDateTextController: retDateTextController, retDateTextController: retDateTextController,
), ),
SizedBox( SizedBox(
width: 300, width: 300,
height: 100, height: 100,
child: MyButton( child: MyButton(
onTap: () { onTap: () {
if (isMedCertFieldsFilled()) { if (isMedCertFieldsFilled()) {
generateMedCert(); generateMedCert();
Navigator.pop(context); Navigator.pop(context);
} else { } else {
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return const MyErrorMessage( return const MyErrorMessage(
errorType: "Input Error"); errorType: "Input Error");
}, },
); );
} }
}, },
buttonText: "Add Note")) buttonText: "Add Note",
buttonColor: Colors.blueAccent,
textColor: Colors.white,
),
)
], ],
), ),
), ),
@@ -289,20 +293,23 @@ class _PatientFilesState extends State<PatientFiles> {
SizedBox( SizedBox(
width: 700, width: 700,
child: MyButton( child: MyButton(
onTap: () async { onTap: () async {
FilePickerResult? result = FilePickerResult? result =
await FilePicker.platform.pickFiles(); await FilePicker.platform.pickFiles();
if (result == null) return; if (result == null) return;
final selectedFile = result.files.first; final selectedFile = result.files.first;
setState(() { setState(() {
selected = selectedFile; selected = selectedFile;
}); });
setState(() { setState(() {
selectedFileController.text = selectedFile.name; selectedFileController.text = selectedFile.name;
}); });
}, },
buttonText: "Select File"), buttonText: "Select File",
buttonColor: Colors.blueAccent,
textColor: Colors.white,
),
), ),
MyTextField( MyTextField(
controller: selectedFileController, controller: selectedFileController,
@@ -311,24 +318,28 @@ class _PatientFilesState extends State<PatientFiles> {
required: true, required: true,
), ),
SizedBox( SizedBox(
width: 300, width: 300,
height: 100, height: 100,
child: MyButton( child: MyButton(
onTap: () { onTap: () {
if (isFileFieldsFilled()) { if (isFileFieldsFilled()) {
uploadSelectedFile(selected); uploadSelectedFile(selected);
Navigator.pop(context); Navigator.pop(context);
} else { } else {
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return const MyErrorMessage( return const MyErrorMessage(
errorType: "Input Error"); errorType: "Input Error");
}, },
); );
} }
}, },
buttonText: "Add Note")) buttonText: "Add Note",
buttonColor: Colors.blueAccent,
textColor: Colors.white,
),
)
], ],
), ),
), ),

View File

@@ -130,24 +130,28 @@ class _PatientNotesState extends State<PatientNotes> {
), ),
), ),
SizedBox( SizedBox(
width: 300, width: 300,
height: 100, height: 100,
child: MyButton( child: MyButton(
onTap: () { onTap: () {
if (isFieldsFilled()) { if (isFieldsFilled()) {
addPatientNoteAPICall(); addPatientNoteAPICall();
Navigator.pop(context); Navigator.pop(context);
} else { } else {
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return const MyErrorMessage( return const MyErrorMessage(
errorType: "Input Error"); errorType: "Input Error");
}, },
); );
} }
}, },
buttonText: "Add Note")) buttonText: "Add Note",
buttonColor: Colors.blueAccent,
textColor: Colors.white,
),
)
], ],
), ),
), ),

View File

@@ -80,18 +80,21 @@ class _ProfileUserUpdateState extends State<ProfileUserUpdate> {
width: 500.0, width: 500.0,
height: 100.0, height: 100.0,
child: MyButton( child: MyButton(
onTap: () { onTap: () {
if (isFieldsFilled()) { if (isFieldsFilled()) {
} else { } else {
showDialog( showDialog(
context: context, context: context,
builder: (context) { builder: (context) {
return const MyErrorMessage(errorType: "Input Error"); return const MyErrorMessage(errorType: "Input Error");
}, },
); );
} }
}, },
buttonText: "Update"), buttonText: "Update",
buttonColor: Colors.blueAccent,
textColor: Colors.white,
),
), ),
], ],
); );

View File

@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:patient_manager/components/homeTileGrid.dart'; import 'package:patient_manager/components/homeTileGrid.dart';
import 'package:patient_manager/components/myAppBar.dart'; import 'package:patient_manager/components/myAppBar.dart';
import 'package:patient_manager/components/homeAppDrawer.dart'; import 'package:patient_manager/components/homeAppDrawer.dart';
import 'package:patient_manager/components/myErrorMessage.dart'; import 'package:patient_manager/components/mySuccessMessage.dart';
import 'package:patient_manager/main.dart'; import 'package:patient_manager/main.dart';
class Home extends StatefulWidget { class Home extends StatefulWidget {
@@ -54,8 +54,10 @@ class _HomeState extends State<Home> {
// .pushNamed('/patient-manager/add', arguments: widget.userEmail); // .pushNamed('/patient-manager/add', arguments: widget.userEmail);
showDialog( showDialog(
context: context, context: context,
builder: (context) => const MyErrorMessage( builder: (context) => const MySuccessMessage(
errorType: "Internet Connection", successType: "Success",
successMessage:
"This is the message when something successful happened.",
), ),
); );
}, },

View File

@@ -284,6 +284,8 @@ class _AddPatientState extends State<AddPatient> {
} }
}, },
buttonText: "Add", buttonText: "Add",
buttonColor: Colors.blueAccent,
textColor: Colors.white,
), ),
), ),
], ],

View File

@@ -226,7 +226,11 @@ class _EditPatientState extends State<EditPatient> {
width: 300, width: 300,
height: 100, height: 100,
child: MyButton( child: MyButton(
onTap: deletePatientApiCall, buttonText: "Delete")) onTap: deletePatientApiCall,
buttonText: "Delete",
buttonColor: Colors.blueAccent,
textColor: Colors.white,
))
], ],
), ),
), ),
@@ -471,6 +475,8 @@ class _EditPatientState extends State<EditPatient> {
} }
}, },
buttonText: "Update", buttonText: "Update",
buttonColor: Colors.blueAccent,
textColor: Colors.white,
), ),
), ),
], ],

View File

@@ -156,8 +156,10 @@ class _RegisterState extends State<Register> {
SizedBox( SizedBox(
width: 500.0, width: 500.0,
child: MyButton( child: MyButton(
onTap: signUserUp, onTap: () {},
buttonText: "Sign Up", buttonText: "Sign Up",
buttonColor: Colors.blueAccent,
textColor: Colors.white,
), ),
), ),
//spacer //spacer

View File

@@ -126,6 +126,8 @@ class _SignInState extends State<SignIn> {
} }
}, },
buttonText: "Sign In", buttonText: "Sign In",
buttonColor: Colors.blueAccent,
textColor: Colors.white,
), ),
), ),
//spacer //spacer