pop up design alignment

This commit is contained in:
2024-07-03 15:58:16 +02:00
parent 8f0134a98f
commit b25583ddf3
4 changed files with 415 additions and 264 deletions

View File

@@ -2,23 +2,13 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:patient_manager/components/buildNotesList.dart';
import 'package:patient_manager/components/myErrorMessage.dart';
import 'package:patient_manager/components/myMLTextInput.dart';
import 'package:patient_manager/components/myTextInput.dart';
import 'package:patient_manager/components/mybutton.dart';
import 'package:patient_manager/objects/notes.dart';
import 'package:http/http.dart' as http;
Future<List<Note>> fetchNotes(String endpoint) async {
final response = await http.get(Uri.parse(endpoint));
if (response.statusCode == 200) {
Iterable l = jsonDecode(response.body);
List<Note> notes = List<Note>.from(l.map((model) => Note.fromJson(model)));
//print("Here notes");
return notes;
} else {
throw Exception('failed to load patients');
}
}
class PatientNotes extends StatefulWidget {
final int patientIndex;
const PatientNotes({super.key, required this.patientIndex});
@@ -34,6 +24,20 @@ class _PatientNotesState extends State<PatientNotes> {
final noteTextController = TextEditingController();
late Future<List<Note>> futueNotes;
Future<List<Note>> fetchNotes(String endpoint) async {
final response = await http.get(Uri.parse(endpoint));
if (response.statusCode == 200) {
Iterable l = jsonDecode(response.body);
List<Note> notes =
List<Note>.from(l.map((model) => Note.fromJson(model)));
//print("Here notes");
return notes;
} else {
internetConnectionPopUp();
throw Exception('failed to load patients');
}
}
Future<void> addPatientNoteAPICall() async {
var response = await http.post(
Uri.parse(apiUrlAddNote),
@@ -55,10 +59,19 @@ class _PatientNotesState extends State<PatientNotes> {
String message = "Successfully added Note";
messagePopUp(message);
} else {
messagePopUp("error");
internetConnectionPopUp();
}
}
void internetConnectionPopUp() {
showDialog(
context: context,
builder: (context) {
return const MyErrorMessage(errorType: "Internet Connection");
},
);
}
void messagePopUp(error) {
showDialog(
context: context,
@@ -70,6 +83,106 @@ class _PatientNotesState extends State<PatientNotes> {
);
}
void addNotePopUp() {
showDialog(
context: context,
builder: (context) => Dialog(
child: Stack(
children: [
Container(
padding: const EdgeInsets.all(10.0),
width: 700.0,
//height: 475.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25.0),
border: Border.all(color: Colors.blueAccent, width: 5.0),
),
child: Column(
//mainAxisSize: MainAxisSize.max,
children: [
const Text(
"Add Note",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.blueAccent,
fontSize: 35.0,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 25.0),
SizedBox(
width: 700,
child: MyTextField(
controller: titleController,
hintText: "Title of Note",
editable: true,
required: true,
),
),
const SizedBox(height: 25.0),
Expanded(
child: MyMLTextField(
controller: noteTextController,
hintText: "Note Details",
editable: true,
required: true,
),
),
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"))
],
),
),
Positioned(
top: 5,
right: 5,
width: 50,
height: 50,
child: IconButton(
onPressed: () {
Navigator.pop(context);
titleController.clear();
noteTextController.clear();
},
icon: const Icon(
Icons.close,
color: Colors.red,
size: 35,
),
),
),
],
),
),
);
}
bool isFieldsFilled() {
if (titleController.text.isEmpty || noteTextController.text.isEmpty) {
return false;
} else {
return true;
}
}
@override
void initState() {
futueNotes = fetchNotes(endpoint + widget.patientIndex.toString());
@@ -115,61 +228,7 @@ class _PatientNotesState extends State<PatientNotes> {
),
IconButton(
onPressed: () {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Add Note"),
],
),
content: Column(
children: [
SizedBox(
width: 700,
child: MyTextField(
controller: titleController,
hintText: "Title of Note",
editable: true,
required: true,
),
),
const SizedBox(
height: 25.0,
),
Expanded(
child: MyMLTextField(
controller: noteTextController,
hintText: "Note Details",
editable: true,
required: true,
),
),
],
),
actions: [
TextButton(
onPressed: () {
addPatientNoteAPICall();
Navigator.pop(context);
//print(widget.patientIndex);
},
child: const Text(
"Submit",
style: TextStyle(
fontWeight: FontWeight.bold),
),
),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text("Cancel"),
)
],
),
);
addNotePopUp();
},
icon: const Icon(Icons.add),
)