Skip to content

Commit

Permalink
add marker and fix blood type
Browse files Browse the repository at this point in the history
  • Loading branch information
HassanGhazy committed Jul 13, 2021
1 parent 3d99c38 commit 9634dea
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 77 deletions.
4 changes: 3 additions & 1 deletion assets/translations/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"welcomeBack": "مرحباً بعودتك",
"notExist": "غير متوفر",
"dateCreatedAt": "التبرع لاول مرة",
"dateUpdatedAt": "آخر تحديث",
"dateUpdatedAt": "الساعة",
"quantity": "الكمية",
"donationDate": "تاريخ التبرع",
"change": "تغيير اللغة",
Expand All @@ -24,5 +24,7 @@
"dateOfBirth": "تاريخ الميلاد",
"identityNumber": "رقم الهوية",
"noDonotion": "لا يوجد أي سجلات تبرع مسجلة",
"bankBlood": "بنك الدم المركزي",
"goto": "اذهب الى",
"hospital": "مستشفى الشفاء"
}
4 changes: 3 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"welcomeBack": "Welcome Back",
"notExist": "Not Available",
"dateCreatedAt": "Donate for the first time",
"dateUpdatedAt": "Last Update",
"dateUpdatedAt": "Time",
"quantity": "Quantity",
"donationDate": "Donation date",
"change": "Change Language",
Expand All @@ -24,5 +24,7 @@
"dateOfBirth": "Date Of Birth",
"identityNumber": "Identity Number",
"basicData": "Basic information",
"bankBlood": "Central blood bank",
"goto": "Go To",
"hospital": "Shifa Hospital"
}
3 changes: 1 addition & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:blood_bank/helper/storge.dart';
import 'package:blood_bank/provider/login_provider.dart';
import 'package:blood_bank/screen/donor_screen.dart';
import 'package:blood_bank/screen/home.dart';
Expand Down Expand Up @@ -36,7 +35,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primaryColor: Colors.red[400],
),
home: (shared.getData("login") == true) ? Home() : Login(),
home: Login(),
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
Expand Down
10 changes: 2 additions & 8 deletions lib/provider/login_provider.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'package:blood_bank/helper/storge.dart';
import 'package:blood_bank/models/donor.dart';
import 'package:blood_bank/models/person_donor.dart';
import 'package:blood_bank/models/user.dart';
Expand All @@ -22,9 +21,6 @@ class LoginProvider with ChangeNotifier {
Future<void> login(
String email, String password, BuildContext context) async {
var response;
bool? log = await shared.getData("login").then((value) {
print("value $value");
});

try {
logInLoading = true;
Expand All @@ -40,15 +36,14 @@ class LoginProvider with ChangeNotifier {
});

if (response.statusCode == 200) {
shared.setData("login", true);
logInLoading = false;
final Map<String, dynamic> extractData =
json.decode(response.body) as Map<String, dynamic>;
print("extractData $extractData");
_token = extractData['access_token'];
_user = data(extractData['data'], _token);
} else {
logInLoading = false;
shared.setData("login", false);
notifyListeners();
return;
}
Expand Down Expand Up @@ -107,6 +102,7 @@ class LoginProvider with ChangeNotifier {
if (response.statusCode == 200) {
final Map<String, dynamic> extractData =
json.decode(response.body) as Map<String, dynamic>;
print(extractData);
_personDonor.addAll(getDataDonor(extractData['data']));
}
} catch (e) {
Expand Down Expand Up @@ -137,8 +133,6 @@ class LoginProvider with ChangeNotifier {
}

void logout(BuildContext context) {
shared.setData("login", false);

Navigator.pushAndRemoveUntil(context,
MaterialPageRoute<dynamic>(builder: (BuildContext context) {
return Login();
Expand Down
14 changes: 9 additions & 5 deletions lib/screen/donor_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Donoecreen extends StatelessWidget {
final String? updatedAt = data['updatedAt'];
final String? createdAt = data['createdAt'];
final String? name = data['name'];
print(updatedAt);
print(updatedAt);
print(updatedAt);
return Scaffold(
backgroundColor: color.grey,
appBar: AppBar(
Expand All @@ -29,16 +32,17 @@ class Donoecreen extends StatelessWidget {
value: "$createdAt",
icon: Icons.date_range),
ListTileWidget(
id: "donationDate".tr(),
value: "$dateDonate".substring(0, dateDonate!.indexOf(' ')),
icon: Icons.date_range),
id: "dateUpdatedAt".tr(),
value:
"${updatedAt!.substring(updatedAt.indexOf('T') + 1, updatedAt.indexOf('.'))}",
icon: Icons.timer),
ListTileWidget(
id: "quantity".tr(),
value: "$quantity",
icon: Icons.add_box_outlined),
ListTileWidget(
id: "dateUpdatedAt".tr(),
value: "$updatedAt",
id: "donationDate".tr(),
value: "$dateDonate".substring(0, dateDonate!.indexOf(' ')),
icon: Icons.date_range),
],
),
Expand Down
92 changes: 55 additions & 37 deletions lib/screen/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Home extends StatefulWidget {
class _HomeState extends State<Home> {
List<PersonDonor> items = [];
bool _isLoaded = false;

String bloodType = "notExist".tr();
@override
void initState() {
super.initState();
Expand All @@ -37,12 +37,39 @@ class _HomeState extends State<Home> {
Widget build(BuildContext context) {
final double height = MediaQuery.of(context).size.height;
final user = Provider.of<LoginProvider>(context, listen: false);
switch (user.user.donor!.bloodType) {
case "1":
bloodType = "A+";
break;
case "2":
bloodType = "A-";
break;
case "3":
bloodType = "B+";
break;
case "4":
bloodType = "B-";
break;
case "5":
bloodType = "AB+";
break;
case "6":
bloodType = "AB-";
break;
case "7":
bloodType = "O+";
break;
case "8":
bloodType = "O-";
break;
default:
bloodType = "notExist".tr();
}
if (!_isLoaded) {
getdata().whenComplete(() {
if (!mounted) return;
setState(() {
_isLoaded = true;
});
_isLoaded = true;
setState(() {});
});
}
return Scaffold(
Expand Down Expand Up @@ -79,40 +106,31 @@ class _HomeState extends State<Home> {
GenericListItem("${user.user.name}", "${user.user.email}"),
),
),
((items.isEmpty))
? Container()
: GenericListItem("basicData".tr(), " "),
((items.isEmpty))
? Container()
: Container(
height: height / 2.5,
child: Card(
child: SingleChildScrollView(
child: Column(
children: [
GenericListItem("firstName".tr(),
user.user.donor?.firstName ?? "notExist".tr()),
GenericListItem("lastName".tr(),
user.user.donor?.lastName ?? "notExist".tr()),
GenericListItem(
"identityNumber".tr(),
user.user.donor?.identityNumber ??
"notExist".tr()),
GenericListItem("address".tr(),
user.user.donor?.address ?? "notExist".tr()),
GenericListItem("bloodType".tr(),
user.user.donor?.bloodType ?? "notExist".tr()),
GenericListItem(
"dateOfBirth".tr(),
user.user.donor?.dateOfBirth ??
"notExist".tr()),
GenericListItem("phone".tr(),
"${user.user.donor?.phone ?? "notExist".tr()}"),
],
),
),
),
GenericListItem("basicData".tr(), " "),
Container(
height: height / 2.5,
child: Card(
child: SingleChildScrollView(
child: Column(
children: [
GenericListItem("firstName".tr(),
user.user.donor?.firstName ?? "notExist".tr()),
GenericListItem("lastName".tr(),
user.user.donor?.lastName ?? "notExist".tr()),
GenericListItem("identityNumber".tr(),
user.user.donor?.identityNumber ?? "notExist".tr()),
GenericListItem("address".tr(),
user.user.donor?.address ?? "notExist".tr()),
GenericListItem("bloodType".tr(), bloodType),
GenericListItem("dateOfBirth".tr(),
user.user.donor?.dateOfBirth ?? "notExist".tr()),
GenericListItem("phone".tr(),
"${user.user.donor?.phone ?? "notExist".tr()}"),
],
),
),
),
),
GenericListItem("donationDate".tr(), "quantity".tr()),
Card(
child: Container(
Expand Down
51 changes: 30 additions & 21 deletions lib/widgets.dart/google_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class MyGoogleMap extends StatefulWidget {

class _MyGoogleMapState extends State<MyGoogleMap> {
static final LatLng _kMapCenter = LatLng(31.524123, 34.443486);
GoogleMapController? mapController;

static final LatLng _kMapBloodCenter =
LatLng(31.52306049379596, 34.437954735976035);
GoogleMapController? mapController;
static final CameraPosition _kInitialPosition =
CameraPosition(target: _kMapCenter, zoom: 15.0, tilt: 0, bearing: 0);

Expand All @@ -21,19 +23,11 @@ class _MyGoogleMapState extends State<MyGoogleMap> {
mapController = _cntlr;
}

void _currentLocation() async {
LocationData? currentLocation;
var location = new Location();
try {
currentLocation = await location.getLocation();
} on Exception {
print("failr");
}

void _bloodBankLocation() async {
mapController!.animateCamera(CameraUpdate.newCameraPosition(
CameraPosition(
bearing: 0,
target: LatLng(currentLocation!.latitude!, currentLocation.longitude!),
target: _kMapBloodCenter,
zoom: 17.0,
),
));
Expand All @@ -45,22 +39,16 @@ class _MyGoogleMapState extends State<MyGoogleMap> {
markerId: MarkerId("hospital1"),
position: _kMapCenter,
infoWindow: InfoWindow(title: 'hospital'.tr())),
Marker(
markerId: MarkerId("hospital2"),
position: _kMapBloodCenter,
infoWindow: InfoWindow(title: 'bankBlood'.tr())),
};
}

@override
Widget build(BuildContext context) {
return new Scaffold(
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: CircleAvatar(
backgroundColor: Colors.black,
child: IconButton(
onPressed: () {
_currentLocation();
},
icon: Icon(Icons.home),
),
),
body: Stack(
children: [
GoogleMap(
Expand All @@ -77,6 +65,27 @@ class _MyGoogleMapState extends State<MyGoogleMap> {
top: 40.0,
),
),
Positioned(
top: 20,
left: 10,
child: ElevatedButton(
onPressed: () {
_bloodBankLocation();
},
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color?>(Colors.red[400])),
child: Row(
children: [
Icon(Icons.bloodtype),
Text(
"${'goto'.tr()} ${'bankBlood'.tr()}",
style: TextStyle(color: Colors.white),
),
],
),
),
)
],
),
);
Expand Down
3 changes: 1 addition & 2 deletions lib/widgets.dart/list_tile_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class ListTileWidget extends StatelessWidget {
id!,
style: TextStyle(fontSize: 14),
),
trailing: (id! == "${"dateCreatedAt".tr()}" ||
id! == "${"dateUpdatedAt".tr()}")
trailing: (id! == "${"dateCreatedAt".tr()}")
? Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
Expand Down

0 comments on commit 9634dea

Please sign in to comment.