Skip to content

Commit

Permalink
Merge pull request #22 from Mehul-Kumar-27/Medicine-Information
Browse files Browse the repository at this point in the history
Issue #21 Feature to see the details of medicines, like prices, how to use, side effects etc.
  • Loading branch information
saptarshiweb authored Feb 12, 2023
2 parents da6de9a + 924547f commit f84b671
Show file tree
Hide file tree
Showing 14 changed files with 2,452 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .dart_tool/dartpad/web_plugin_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
// ignore_for_file: type=lint

import 'package:shared_preferences_web/shared_preferences_web.dart';
import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

void registerPlugins([final Registrar? pluginRegistrar]) {
final Registrar registrar = pluginRegistrar ?? webPluginRegistrar;
SharedPreferencesPlugin.registerWith(registrar);
UrlLauncherPlugin.registerWith(registrar);
registrar.registerMessageHandler();
}
55 changes: 55 additions & 0 deletions .dart_tool/flutter_build/dart_plugin_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
import 'dart:io'; // flutter_ignore: dart_io_import.
import 'package:path_provider_android/path_provider_android.dart';
import 'package:shared_preferences_android/shared_preferences_android.dart';
import 'package:url_launcher_android/url_launcher_android.dart';
import 'package:path_provider_ios/path_provider_ios.dart';
import 'package:shared_preferences_ios/shared_preferences_ios.dart';
import 'package:url_launcher_ios/url_launcher_ios.dart';
import 'package:path_provider_linux/path_provider_linux.dart';
import 'package:shared_preferences_linux/shared_preferences_linux.dart';
import 'package:url_launcher_linux/url_launcher_linux.dart';
import 'package:path_provider_macos/path_provider_macos.dart';
import 'package:shared_preferences_macos/shared_preferences_macos.dart';
import 'package:url_launcher_macos/url_launcher_macos.dart';
import 'package:path_provider_windows/path_provider_windows.dart';
import 'package:shared_preferences_windows/shared_preferences_windows.dart';
import 'package:url_launcher_windows/url_launcher_windows.dart';

@pragma('vm:entry-point')
class _PluginRegistrant {
Expand Down Expand Up @@ -43,6 +48,16 @@ class _PluginRegistrant {
rethrow;
}

try {
UrlLauncherAndroid.registerWith();
} catch (err) {
print(
'`url_launcher_android` threw an error: $err. '
'The app may not function as expected until you remove this plugin from pubspec.yaml'
);
rethrow;
}

} else if (Platform.isIOS) {
try {
PathProviderIOS.registerWith();
Expand All @@ -64,6 +79,16 @@ class _PluginRegistrant {
rethrow;
}

try {
UrlLauncherIOS.registerWith();
} catch (err) {
print(
'`url_launcher_ios` threw an error: $err. '
'The app may not function as expected until you remove this plugin from pubspec.yaml'
);
rethrow;
}

} else if (Platform.isLinux) {
try {
PathProviderLinux.registerWith();
Expand All @@ -85,6 +110,16 @@ class _PluginRegistrant {
rethrow;
}

try {
UrlLauncherLinux.registerWith();
} catch (err) {
print(
'`url_launcher_linux` threw an error: $err. '
'The app may not function as expected until you remove this plugin from pubspec.yaml'
);
rethrow;
}

} else if (Platform.isMacOS) {
try {
PathProviderMacOS.registerWith();
Expand All @@ -106,6 +141,16 @@ class _PluginRegistrant {
rethrow;
}

try {
UrlLauncherMacOS.registerWith();
} catch (err) {
print(
'`url_launcher_macos` threw an error: $err. '
'The app may not function as expected until you remove this plugin from pubspec.yaml'
);
rethrow;
}

} else if (Platform.isWindows) {
try {
PathProviderWindows.registerWith();
Expand All @@ -127,6 +172,16 @@ class _PluginRegistrant {
rethrow;
}

try {
UrlLauncherWindows.registerWith();
} catch (err) {
print(
'`url_launcher_windows` threw an error: $err. '
'The app may not function as expected until you remove this plugin from pubspec.yaml'
);
rethrow;
}

}
}
}
823 changes: 823 additions & 0 deletions assets/data/medicine.csv

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'dart:async';
import 'package:bloc/bloc.dart';

import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:medi_app/network/medicines_api.dart';
part 'lab_test_list_event.dart';
part 'lab_test_list_state.dart';

class MedicineListBloc extends Bloc<MedicineListEvent, MedicineListState> {
MedicineInformation medicineInformation;
MedicineListBloc(this.medicineInformation)
: super(LoadingMedicineDataState());

late List<List<dynamic>> medicineData;
late List<List<dynamic>> filterMedicineData;

@override
Stream<MedicineListState> mapEventToState(
MedicineListEvent event,
) async* {
if (event is GetMedicineData) {
yield LoadingMedicineDataState();

try {
medicineData = await medicineInformation.getListOfMedicines();
filterMedicineData = medicineData;
yield LoadedListState(medicineData);
} catch (e) {
yield ShowSnackBar(e.toString());
yield ErrorState(e.toString());
}
} else if (event is SearchTestData) {
try {
List<List<dynamic>> copyList = medicineData;

// hospitalCompareData = copyList;
filterMedicineData = [];

for (var element in copyList) {
if (element[0].toLowerCase().contains(event.query)) {
filterMedicineData.add(element);
}
}

if (filterMedicineData.isEmpty) {
yield ErrorState('No Result Found');
} else {
yield LoadedListState(filterMedicineData);
}
} catch (e) {
yield ErrorState('something wrong');
}
}
}
}

class MedicineInformation {
Future getListOfMedicines() async {
MedicineAPIClient medicineAPIClient = MedicineAPIClient();

return medicineAPIClient.fetchMedicinesFromAssets();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
part of 'lab_test_list_bloc.dart';

abstract class MedicineListEvent extends Equatable {
const MedicineListEvent();
}

class GetMedicineData extends MedicineListEvent {
@override
List<Object> get props => [];
}

class SearchTestData extends MedicineListEvent {
final String query;

SearchTestData(this.query);
@override
List<Object> get props => [query];
}

// class UpdateTestToGetInformation extends LabTestListEvent {
// final int index;
// // final bool filteredlist;
// UpdateTestToGetInformation(this.index);
// @override
// List<Object> get props => [index];
// }

// class SelectedTheTestToGetInformation extends LabTestListEvent {
// final LabInformationScreenBloc labInformationScreenBloc;
// final int index;
// SelectedTheTestToGetInformation(this.labInformationScreenBloc, this.index);
// @override
// List<Object> get props => [labInformationScreenBloc, index];
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
part of 'lab_test_list_bloc.dart';

abstract class MedicineListState extends Equatable {
const MedicineListState();
}

class LoadingMedicineDataState extends MedicineListState {
@override
// TODO: implement props
List<Object> get props => [];
}

class ErrorState extends MedicineListState {
final String message;
@override
// TODO: implement props
List<Object> get props => [message];

ErrorState(this.message);
}

class ShowSnackBar extends MedicineListState {
final String message;
ShowSnackBar(this.message);
@override
// TODO: implement props
List<Object> get props => [];
}

class LoadedListState extends MedicineListState {
final List<List<dynamic>> labTestListData;

LoadedListState(this.labTestListData);

@override
List<Object> get props => [labTestListData];
}
29 changes: 29 additions & 0 deletions lib/network/medicines_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;

class MedicineAPIClient {
Future fetchMedicinesFromAssets() async {
final myData = await rootBundle.loadString("assets/data/medicine.csv");
List<dynamic> myDataList = myData.split("\n");
List<List<dynamic>> rowsAsListOfValues = [];
myDataList.forEach((element) {
List<dynamic> values = [];
element.split(",").forEach((elementValue) {
values.add(elementValue);
});

if (values.length > 2 &&
values[0] != null &&
values[0] != '''"''' &&
values[0].toString().length <= 35 &&
"${values[0]}".isNotEmpty) {
rowsAsListOfValues.add(values);
}
});
rowsAsListOfValues.sort((a, b) {
return a[0].toLowerCase().compareTo(b[0].toLowerCase());
});

return rowsAsListOfValues;
}
}
6 changes: 5 additions & 1 deletion lib/pages/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:lottie/lottie.dart';
import 'package:medi_app/constants/color_codes.dart';
import 'package:medi_app/controllers/db_helper.dart';
import 'package:medi_app/pages/medicine/medicine_list.dart';

class Dashboard extends StatefulWidget {
const Dashboard({Key? key}) : super(key: key);
Expand Down Expand Up @@ -211,7 +212,10 @@ class _DashboardState extends State<Dashboard> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
element(FontAwesomeIcons.kitMedical, 'Pill ID'),
GestureDetector(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=>Medicines()));
},child: element(FontAwesomeIcons.kitMedical, 'Pill ID')),
element(FontAwesomeIcons.check, 'Rx Check'),
element(FontAwesomeIcons.disease, 'Diseases'),
element(FontAwesomeIcons.heartCircleCheck, 'Treatment')
Expand Down
Loading

0 comments on commit f84b671

Please sign in to comment.