Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added submit button + db connection
  • Loading branch information
Shariq Khan committed Jun 20, 2022
1 parent 3e1a9f3 commit e2ad8ad
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 11 deletions.
28 changes: 27 additions & 1 deletion README.md
@@ -1,3 +1,29 @@
# SAFER: Storm Assistance for Emergency Resilience

This is the code for the SAFER app built for Prof. Carolyn Lin.
This is the `flutter` code for the SAFER app built for Prof. Carolyn Lin.

## Common Commands

### To check if `flutter` is configured properly
```
flutter doctor
```

### To run/build the app
```
flutter run
```

### To build an `APK` file:
```
flutter build apk --release
```

### I swear it was working before...
```
rm pubspec.lock
flutter clean
flutter clean cache
flutter pub cache clean
flutter run
```
8 changes: 7 additions & 1 deletion ios/Podfile.lock
@@ -1,16 +1,21 @@
PODS:
- device_info_plus (0.0.1):
- Flutter
- Flutter (1.0.0)
- shared_preferences (0.0.1):
- Flutter
- url_launcher (0.0.1):
- Flutter

DEPENDENCIES:
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- Flutter (from `Flutter`)
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
- url_launcher (from `.symlinks/plugins/url_launcher/ios`)

EXTERNAL SOURCES:
device_info_plus:
:path: ".symlinks/plugins/device_info_plus/ios"
Flutter:
:path: Flutter
shared_preferences:
Expand All @@ -19,9 +24,10 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/url_launcher/ios"

SPEC CHECKSUMS:
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
shared_preferences: af6bfa751691cdc24be3045c43ec037377ada40d
url_launcher: 6fef411d543ceb26efce54b05a0a40bfd74cbbef
url_launcher: a1c0cc845906122c4784c542523d8cacbded5626

PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c

Expand Down
38 changes: 36 additions & 2 deletions lib/screens/safer_main_menu/personal_risk.dart
@@ -1,6 +1,8 @@
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:safer/widgets/widget.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'dart:io';

class PersonalRisk extends StatefulWidget {
final String title;
Expand Down Expand Up @@ -105,14 +107,25 @@ class _PersonalRiskState extends State<PersonalRisk> {
super.initState();
}

Future<String> _getId() async {
var deviceInfo = DeviceInfoPlugin();
if (Platform.isIOS) {
var iosDeviceInfo = await deviceInfo.iosInfo;
return iosDeviceInfo.identifierForVendor; // unique ID on iOS
} else if (Platform.isAndroid) {
var androidDeviceInfo = await deviceInfo.androidInfo;
return androidDeviceInfo.androidId; // unique ID on Android
}
}

void senddata() async {
setState(() {
_loading = true;
});
await http.post(
"https://stormassistance.research.uconn.edu/personal_risk.php",
body: {
"userId": "test",
"phoneID": await _getId(),
"specialNeeds": _specialNeeds.join(", "),
"priorFlooding": _priorFlooding.join(", "),
"priorDamages": _priorDamages.join(", "),
Expand Down Expand Up @@ -149,7 +162,7 @@ class _PersonalRiskState extends State<PersonalRisk> {
ListTile(
leading: CircleAvatar(
backgroundImage:
AssetImage('assets/images/safety.png')),
AssetImage('assets/images/safety.png')),
title: Text('Personal Risk in a Storm'),
subtitle: RichText(
text: TextSpan(
Expand All @@ -170,6 +183,27 @@ class _PersonalRiskState extends State<PersonalRisk> {
],
),
),
Card(
clipBehavior: Clip.antiAlias,
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8),
),
ListTile(
title: RichText(
text: TextSpan(
style: TextStyle(
color: Colors.black, fontSize: 20, fontFamily: 'Raleway'),
text:
'Your Risk Score: ${_riskScore.values.reduce((sum, element) => sum + element)}',
))),
Padding(
padding: const EdgeInsets.all(8),
),
],
),
),
Card(
clipBehavior: Clip.antiAlias,
child: Column(
Expand Down
86 changes: 79 additions & 7 deletions lib/screens/safer_main_menu/property_risk.dart
@@ -1,5 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_spinbox/flutter_spinbox.dart';
import 'package:safer/widgets/widget.dart';
import 'package:http/http.dart' as http;
import 'package:device_info_plus/device_info_plus.dart';
import 'dart:io';

class PropertyRisk extends StatefulWidget {
final String title;
Expand All @@ -13,6 +17,8 @@ class PropertyRisk extends StatefulWidget {
}

class _PropertyRiskState extends State<PropertyRisk> {
bool _loading = false;

Map<String, int> _riskScore = {
"buildingStructure": 0,
"roofAge": 0,
Expand All @@ -28,13 +34,55 @@ class _PropertyRiskState extends State<PropertyRisk> {
"treeFalling": 0,
};

String _dropDownValue;
String homeType;
String buildingAge;

@override
void initState() {
super.initState();
}

Future<String> _getId() async {
var deviceInfo = DeviceInfoPlugin();
if (Platform.isIOS) {
var iosDeviceInfo = await deviceInfo.iosInfo;
return iosDeviceInfo.identifierForVendor; // unique ID on iOS
} else if (Platform.isAndroid) {
var androidDeviceInfo = await deviceInfo.androidInfo;
return androidDeviceInfo.androidId; // unique ID on Android
}
}

void senddata() async {
setState(() {
_loading = true;
});
await http.post(
"https://stormassistance.research.uconn.edu/property_risk.php",
body: {
"phoneID": await _getId(),
"homeType": homeType,
"buildingAge": buildingAge.toString(),
"buildingStructure": _riskScore["buildingStructure"].toString(),
"roofAge": _riskScore["roofAge"].toString(),
"elevation": _riskScore["elevation"].toString(),
"flooding": _riskScore["flooding"].toString(),
"drainage": _riskScore["drainage"].toString(),
"waterDamage": _riskScore["waterDamage"].toString(),
"window": _riskScore["window"].toString(),
"sewage": _riskScore["sewage"].toString(),
"waterSupply": _riskScore["waterSupply"].toString(),
"fuelSupply": _riskScore["fuelSupply"].toString(),
"itemSecurity": _riskScore["itemSecurity"].toString(),
"treeFalling": _riskScore["treeFalling"].toString(),
"riskScore":
"${_riskScore.values.reduce((sum, element) => sum + element)}",
});
setState(() {
_loading = false;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -90,14 +138,14 @@ class _PropertyRiskState extends State<PropertyRisk> {
backgroundImage: AssetImage('assets/images/house.png')),
title: Container(
child: DropdownButton(
hint: _dropDownValue == null
? Text('Dropdown')
hint: homeType == null
? Text('Home Type')
: Text(
_dropDownValue,
homeType,
style: TextStyle(color: Colors.blue),
),
isExpanded: true,
iconSize: 30.0,
iconSize: 40.0,
items: ['One', 'Two'].map(
(val) {
return DropdownMenuItem<String>(
Expand All @@ -109,15 +157,23 @@ class _PropertyRiskState extends State<PropertyRisk> {
onChanged: (val) {
setState(
() {
_dropDownValue = val;
homeType = val;
},
);
},
)),
subtitle: Container(
child: TextFormField(
decoration: InputDecoration(
labelText: 'Building Age', suffixText: 'years'),
labelText: 'Building Age',
suffixText: 'years',
contentPadding: EdgeInsets.only(left: 1),
),
onChanged: (val) {
setState(() {
buildingAge = val;
});
},
),
),
),
Expand Down Expand Up @@ -491,6 +547,22 @@ class _PropertyRiskState extends State<PropertyRisk> {
],
),
),
Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 15,
bottom: 15,
),
child: AppButton(
onPressed: () {
senddata();
},
loading: _loading,
disableTouchWhenLoading: true,
text: 'Submit',
),
)
],
),
);
Expand Down
58 changes: 58 additions & 0 deletions lib/screens/safer_main_menu/supplies.dart
Expand Up @@ -2,6 +2,10 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinbox/flutter_spinbox.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:safer/widgets/widget.dart';
import 'package:http/http.dart' as http;
import 'package:device_info_plus/device_info_plus.dart';
import 'dart:io';

class Supplies extends StatefulWidget {
final String title;
Expand All @@ -15,6 +19,8 @@ class Supplies extends StatefulWidget {
}

class _SuppliesState extends State<Supplies> {
bool _loading = false;

Map<String, int> _readinessScore = {
"necessities": 0,
"food": 0,
Expand All @@ -33,6 +39,42 @@ class _SuppliesState extends State<Supplies> {
super.initState();
}

Future<String> _getId() async {
var deviceInfo = DeviceInfoPlugin();
if (Platform.isIOS) {
var iosDeviceInfo = await deviceInfo.iosInfo;
return iosDeviceInfo.identifierForVendor; // unique ID on iOS
} else if (Platform.isAndroid) {
var androidDeviceInfo = await deviceInfo.androidInfo;
return androidDeviceInfo.androidId; // unique ID on Android
}
}

void senddata() async {
setState(() {
_loading = true;
});
await http
.post("https://stormassistance.research.uconn.edu/supplies.php", body: {
"phoneID": await _getId(),
"necessities": _readinessScore["necessities"].toString(),
"food": _readinessScore["food"].toString(),
"water": _readinessScore["water"].toString(),
"safety": _readinessScore["safety"].toString(),
"medical": _readinessScore["medical"].toString(),
"care": _readinessScore["care"].toString(),
"tools": _readinessScore["tools"].toString(),
"communication": _readinessScore["communication"].toString(),
"documents": _readinessScore["documents"].toString(),
"power": _readinessScore["power"].toString(),
"readinessScore":
"${_readinessScore.values.reduce((sum, element) => sum + element)}",
});
setState(() {
_loading = false;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -546,6 +588,22 @@ class _SuppliesState extends State<Supplies> {
],
),
),
Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 15,
bottom: 15,
),
child: AppButton(
onPressed: () {
senddata();
},
loading: _loading,
disableTouchWhenLoading: true,
text: 'Submit',
),
)
],
),
);
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Expand Up @@ -27,6 +27,7 @@ dependencies:
intro_views_flutter: ^2.8.1
url_launcher: ^5.4.0
flutter_spinbox: ^0.5.0
device_info_plus: ^3.2.3

# flutter_spinbox depends on intl ^0.16.1 but flutter_localizations depends
# on 0.17.0, so we neeed to override the intl dependency after flutter_spinbox
Expand Down

0 comments on commit e2ad8ad

Please sign in to comment.