Skip to content
Snippets Groups Projects
Commit dfa40c1f authored by Thi Huyen Trang Nguyen's avatar Thi Huyen Trang Nguyen
Browse files

Merge branch 'KAT-50' into 'master'

Kat 50 add database and MyHomePage2.dart

See merge request nguyen17/katapp!1
parents 70205aba d8943ed5
No related branches found
No related tags found
1 merge request!1Master
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:rescueapp/CameraAcess.dart';
import 'model-patient/patient.dart';
class MyHomePage2 extends StatefulWidget {
MyHomePage2({this.patient, this.patientIndex, Key key, this.title}) : super(key: key);
final String title;
final Patient patient;
final int patientIndex;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage2> {
bool _isAmbilatory;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('KatApp2'),
),
body: Padding(
padding: EdgeInsets.symmetric(horizontal:40,vertical: 10),
child: Column(
children: <Widget>[
SizedBox(
height: 40,
child: Container(
decoration: BoxDecoration(
color: Colors.grey[500]
),
alignment: Alignment.center,
child:Text('Ist der Patient gehfähig?' , style: TextStyle(fontSize: 22, color: Colors.blue[900])),
)
),
SizedBox(
height: 40,
child: Container(
decoration: BoxDecoration(
color: Colors.grey[500]
),
alignment: Alignment.center,
child:Text('Nein', style: TextStyle(fontSize: 20, color: Colors.blue [900], backgroundColor: Colors.grey[500])),
)),
SizedBox(
height: 150,),
SizedBox(
height: 50,
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border(
left: BorderSide(color: Colors.red, width: 2),
right: BorderSide(color: Colors.red, width: 2),
top: BorderSide(color: Colors.red, width: 2),
),),
child:Text('Kategorie A', style: TextStyle(fontSize: 22, fontWeight: FontWeight.w700, color: Colors.blue[900], backgroundColor: Colors.white)),
)),
SizedBox(
height: 50,
width: 500,
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border(
left: BorderSide(color: Colors.red, width: 2),
right: BorderSide(color: Colors.red, width: 2),
bottom: BorderSide(color: Colors.red, width: 2),
),),
child:Text('Spontanatmung vorhanden?', style: TextStyle(fontSize: 22, fontWeight: FontWeight.w700, color: Colors.blue[900], backgroundColor: Colors.white)),
)),
SizedBox(
height: 100,
),
SizedBox(
child: Container(
width: double.infinity,
alignment: Alignment.center,
child:RaisedButton(child: new Text('Ja'), color: Colors.blue,
onPressed: () {
setState(() {
_isAmbilatory = true;
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CameraAccess()),
);
});
}))),
SizedBox(
child: Container(
alignment: Alignment.center,
child:RaisedButton(child: new Text('Nein'), color: Colors.blue,
onPressed: () {
setState(() {
_isAmbilatory = false;
});
}))),
SizedBox(
width: 200,
child: Container(
alignment: Alignment.center,
child:ElevatedButton(child: new Text('Zurück'), onPressed: () {
Navigator.pop(context);
}))),
],
),
),
);
}
}
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:rescueapp/CameraAcess.dart';
import 'model-patient/patient.dart';
class MyHomePage3 extends StatefulWidget {
MyHomePage3({this.patient, this.patientIndex, Key key, this.title}) : super(key: key);
final String title;
final Patient patient;
final int patientIndex;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage3> {
bool _isAmbilatory;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('KatApp2'),
),
body: Padding(
padding: EdgeInsets.symmetric(horizontal:40,vertical: 10),
child: Column(
children: <Widget>[
SizedBox(
height: 40,
child: Container(
decoration: BoxDecoration(
color: Colors.grey[500]
),
alignment: Alignment.center,
child:Text('Ist der Patient gehfähig?' , style: TextStyle(fontSize: 22, color: Colors.blue[900])),
)
),
SizedBox(
height: 40,
child: Container(
decoration: BoxDecoration(
color: Colors.grey[500]
),
alignment: Alignment.center,
child:Text('Nein', style: TextStyle(fontSize: 20, color: Colors.blue [900], backgroundColor: Colors.grey[500])),
)),
SizedBox(
height: 40,
child: Container(
decoration: BoxDecoration(
color: Colors.grey[500]
),
alignment: Alignment.center,
child:Text('A:Spontanatmung vorhanden?', style: TextStyle(fontSize: 20, color: Colors.blue [900], backgroundColor: Colors.grey[500])),
)),
SizedBox(
height: 40,
child: Container(
decoration: BoxDecoration(
color: Colors.grey[500]
),
alignment: Alignment.center,
child:Text('Nein', style: TextStyle(fontSize: 20, color: Colors.blue [900], backgroundColor: Colors.grey[500])),
)),
SizedBox(
height: 100,),
SizedBox(
height: 50,
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border(
left: BorderSide(color: Colors.red, width: 2),
right: BorderSide(color: Colors.red, width: 2),
top: BorderSide(color: Colors.red, width: 2),
),),
child:Text('Kategorie A', style: TextStyle(fontSize: 22, fontWeight: FontWeight.w700, color: Colors.blue[900], backgroundColor: Colors.white)),
)),
SizedBox(
height: 50,
width: 500,
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border(
left: BorderSide(color: Colors.red, width: 2),
right: BorderSide(color: Colors.red, width: 2),
bottom: BorderSide(color: Colors.red, width: 2),
),),
child:Text('Nach Öffnung der Atemwege?', style: TextStyle(fontSize: 22, fontWeight: FontWeight.w700, color: Colors.blue[900], backgroundColor: Colors.white)),
)),
SizedBox(
height: 100,
),
SizedBox(
child: Container(
width: double.infinity,
alignment: Alignment.center,
child:RaisedButton(child: new Text('Ja'), color: Colors.blue,
onPressed: () {
setState(() {
_isAmbilatory = true;
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CameraAccess()),
);
});
}))),
SizedBox(
child: Container(
alignment: Alignment.center,
child:RaisedButton(child: new Text('Nein'), color: Colors.blue,
onPressed: () {
setState(() {
_isAmbilatory = false;
});
}))),
SizedBox(
width: 200,
child: Container(
alignment: Alignment.center,
child:ElevatedButton(child: new Text('Zurück'), onPressed: () {
Navigator.pop(context);
}))),
],
),
),
);
}
}
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:rescueapp/events-patient/add_patient.dart';
import 'package:rescueapp/events-patient/delete_patient.dart';
import 'package:rescueapp/events-patient/patient_event.dart';
import 'package:rescueapp/events-patient/set_patient.dart';
import 'package:rescueapp/events-patient/update_patient.dart';
import 'package:rescueapp/model-patient/patient.dart';
class PatientBloc extends Bloc<PatientEvent, List<Patient>> {
@override
List<Patient> get initialState => List<Patient>();
// events wird definiert durch PatientEvent.
// mapEventToState wird aufgerufen um das bestimmte event mit einem bestimmten status zu definieren
@override
Stream<List<Patient>> mapEventToState(PatientEvent event) async* {
if (event is SetPatient) {
yield event.patientList;
} else if (event is AddPatient) {
List<Patient> newState = List.from(state);
if (event.newPatient != null) {
newState.add(event.newPatient);
}
yield newState;
} else if (event is DeletePatient) {
List<Patient> newState = List.from(state);
newState.removeAt(event.patientIndex);
yield newState;
} else if (event is UpdatePatient) {
List<Patient> newState = List.from(state);
newState[event.patientIndex] = event.newPatient;
yield newState;
}
}
}
\ No newline at end of file
import 'package:path/path.dart';
import 'package:rescueapp/model-patient/patient.dart';
import 'package:sqflite/sqflite.dart';
import 'package:sqflite/sqlite_api.dart';
//Einige asynchronous Operationen sind:
// Daten über ein Netzwerk abrufen
// Eine Datenbank zu schreiben
//Asynchronisierung
// Daten aus einem File lesen: Async means that this function is asynchronous and you might need to wait a bit to get its result.
// Await literally means - wait here until this function is finished and you will get its return value.
class DatabaseProvider {
static const String TABLE_PATIENT = "patient";
static const String COLUMN_ID = "id";
static const String COLUMN_NAME = "name";
static const String COLUMN_BIRTHDAY = "geburtsdatum";
static const String COLUMN_ISAMBILATORY = "isGehfähig";
static const String COLUMN_IMAGEPATH = "imagePath";
static const String COLUMN_CATEGORIE = "category";
// Constructor
DatabaseProvider._();
static final DatabaseProvider db = DatabaseProvider._();
Database _database;
Future <Database> get database async {
print("database getter called");
if (_database != null) {
return _database;
}
_database = await createDatabase();
return _database;
}
Future<Database> createDatabase() async {
String dbPath = await getDatabasesPath();
return await openDatabase(
join(dbPath, 'patientDB.db'),
version: 1,
onCreate: (Database database, int version) async {
print("Creating patient table");
await database.execute(
"CREATE TABLE $TABLE_PATIENT ("
"$COLUMN_ID INTEGER PRIMARY KEY,"
"$COLUMN_NAME TEXT,"
"$COLUMN_BIRTHDAY TEXT,"
"$COLUMN_ISAMBILATORY INTEGER,"
"$COLUMN_IMAGEPATH STRING,"
"$COLUMN_CATEGORIE STRING,"
")",
);
},
);
}
Future<List<Patient>> getPatients() async {
final db = await database;
var patients = await db
.query(TABLE_PATIENT, columns: [COLUMN_ID, COLUMN_NAME, COLUMN_IMAGEPATH,COLUMN_BIRTHDAY, COLUMN_ISAMBILATORY, COLUMN_CATEGORIE]);
List<Patient> patientList = List<Patient>();
patients.forEach((currentPatient) {
Patient patient = Patient.fromMap(currentPatient);
patientList.add(patient);
});
return patientList;
}
Future<Patient> insert(Patient patient) async {
final db = await database;
patient.id = await db.insert(TABLE_PATIENT, patient.toMap());
return patient;
}
Future<int> delete(int id) async {
final db = await database;
return await db.delete(
TABLE_PATIENT,
where: "id = ?",
whereArgs: [id],
);
}
Future<int> update(Patient patient) async {
final db = await database;
return await db.update(
TABLE_PATIENT,
patient.toMap(),
where: "id = ?",
whereArgs: [patient.id],
);
}
}
\ No newline at end of file
import 'package:rescueapp/events-patient/patient_event.dart';
import 'package:rescueapp/model-patient/patient.dart';
class AddPatient extends PatientEvent {
Patient newPatient;
AddPatient(Patient patient) {
newPatient = patient;
}
}
import 'package:rescueapp/events-patient/patient_event.dart';
class DeletePatient extends PatientEvent {
int patientIndex;
DeletePatient(int index) {
patientIndex = index;
}
}
\ No newline at end of file
abstract class PatientEvent {}
\ No newline at end of file
import 'package:rescueapp/events-patient/patient_event.dart';
import 'package:rescueapp/model-patient/patient.dart';
class SetPatient extends PatientEvent {
List<Patient> patientList;
SetPatient(List<Patient> patient) {
patientList = patient;
}
}
\ No newline at end of file
import 'package:rescueapp/events-patient/patient_event.dart';
import 'package:rescueapp/model-patient/patient.dart';
class UpdatePatient extends PatientEvent {
Patient newPatient;
int patientIndex;
UpdatePatient(int index, Patient patient) {
newPatient = patient;
patientIndex = index;
}
}
\ No newline at end of file
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'MyHomePage2.dart';
void main() { void main() {
runApp(MyApp()); runApp(MyApp());
} }
...@@ -11,103 +14,58 @@ class MyApp extends StatelessWidget { ...@@ -11,103 +14,58 @@ class MyApp extends StatelessWidget {
return MaterialApp( return MaterialApp(
title: 'KatApp', title: 'KatApp',
theme: ThemeData( theme: ThemeData(
// This is the theme of your application. primarySwatch: Colors.blue,
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
), ),
home: MyHomePage(title: 'KatApp Home Page'), home: MyHomePage()
//home: MyHomePage(title: 'KatApp Home Page'),
); );
} }
} }
class MyHomePage extends StatefulWidget { class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by title: Text('KatApp Startseite'),
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
), ),
body: Center(
// Center is a layout widget. It takes a single child and positions it body: Center(
// in the middle of the parent.
child: Column( child: Column(
// Column is also a layout widget. It takes a list of children and children: <Widget>[
// arranges them vertically. By default, it sizes itself to fit its SizedBox(
// children horizontally, and tries to be as tall as its parent. height: 250,
// ),
// Invoke "debug painting" (press "p" in the console, choose the SizedBox(
// "Toggle Debug Paint" action from the Flutter Inspector in Android child: Container (
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code) child: RaisedButton(
// to see the wireframe for each widget. child: Text('ÜBUNG', style: TextStyle(fontSize: 22, color: Colors.white,)),
// color: Colors.green,
// Column has various properties to control how it sizes itself and onPressed: () {
// how it positions its children. Here we use mainAxisAlignment to Navigator.push(
// center the children vertically; the main axis here is the vertical context,
// axis because Columns are vertical (the cross axis would be MaterialPageRoute(builder: (context) => MyHomePage2()),
// horizontal). );
mainAxisAlignment: MainAxisAlignment.center, },
children: <Widget>[ ))
Text( ),
'You have pushed the button this many times:', SizedBox (
), height: 20,
Text( ),
'$_counter', SizedBox (
style: Theme.of(context).textTheme.headline4, child: Container (
), child: RaisedButton(
], child: Text('REAL',style: TextStyle(fontSize: 22, color: Colors.white)),
color: Colors.red,
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MyHomePage()),
);}
) ),),
],
), ),
), ),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
); );
} }
} }
import 'package:rescueapp/database/database_provide.dart';
class Patient {
int id;
String name;
String birthday;
bool isAmbilatory;
String imagePath;
String category;
Patient({this.id, this.name, this.birthday, this.isAmbilatory, this.imagePath, this.category});
//converts to map
Map<String, dynamic> toMap() {
var map = <String, dynamic>{
DatabaseProvider.COLUMN_NAME: name,
DatabaseProvider.COLUMN_BIRTHDAY: birthday,
DatabaseProvider.COLUMN_ISAMBILATORY: isAmbilatory ? 1 : 0,
DatabaseProvider.COLUMN_IMAGEPATH: imagePath,
DatabaseProvider.COLUMN_CATEGORIE: category,
};
if (id != null) {
map[DatabaseProvider.COLUMN_ID] = id;
}
return map;
}
Patient.fromMap(Map<String, dynamic> map) {
id = map[DatabaseProvider.COLUMN_ID];
name = map[DatabaseProvider.COLUMN_NAME];
birthday = map[DatabaseProvider.COLUMN_BIRTHDAY];
isAmbilatory = map[DatabaseProvider.COLUMN_ISAMBILATORY] == 1;
imagePath = map[DatabaseProvider.COLUMN_IMAGEPATH];
category = map[DatabaseProvider.COLUMN_CATEGORIE];
}
}
\ No newline at end of file
...@@ -24,6 +24,15 @@ dependencies: ...@@ -24,6 +24,15 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
camera: ^0.5.7+2
image_picker: ^0.6.2+3
path_provider:
sqflite: ^1.2.0
path: ^1.6.4
share: ^0.6.5+4
shared_preferences: ^0.5.6+1
video_player: ^0.10.0
flutter_bloc: ^3.2.0
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment