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 {
final void Function() onTap;
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
Widget build(BuildContext context) {
@@ -13,17 +21,17 @@ class MyButton extends StatelessWidget {
child: ElevatedButton(
onPressed: onTap,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blueAccent,
backgroundColor: buttonColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
),
child: Text(
buttonText,
style: const TextStyle(
style: TextStyle(
//fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.white,
color: textColor,
),
),
),

View File

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

View File

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

View File

@@ -80,18 +80,21 @@ class _ProfileUserUpdateState extends State<ProfileUserUpdate> {
width: 500.0,
height: 100.0,
child: MyButton(
onTap: () {
if (isFieldsFilled()) {
} else {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(errorType: "Input Error");
},
);
}
},
buttonText: "Update"),
onTap: () {
if (isFieldsFilled()) {
} else {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(errorType: "Input Error");
},
);
}
},
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/myAppBar.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';
class Home extends StatefulWidget {
@@ -54,8 +54,10 @@ class _HomeState extends State<Home> {
// .pushNamed('/patient-manager/add', arguments: widget.userEmail);
showDialog(
context: context,
builder: (context) => const MyErrorMessage(
errorType: "Internet Connection",
builder: (context) => const MySuccessMessage(
successType: "Success",
successMessage:
"This is the message when something successful happened.",
),
);
},

View File

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

View File

@@ -226,7 +226,11 @@ class _EditPatientState extends State<EditPatient> {
width: 300,
height: 100,
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",
buttonColor: Colors.blueAccent,
textColor: Colors.white,
),
),
],

View File

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

View File

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