From faaa6109142ad28866bb71e5fac16ece568105d6 Mon Sep 17 00:00:00 2001 From: viradhanus Date: Sun, 28 Feb 2021 16:51:44 +0530 Subject: [PATCH 1/4] ui improved --- android/app/build.gradle | 4 +- android/build.gradle | 2 +- .../medicine/medicine_recognition_ML_Kit.dart | 445 +++++++++++++++--- 3 files changed, 394 insertions(+), 57 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 784dd0e..df329ef 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -23,7 +23,7 @@ if (flutterVersionName == null) { apply plugin: 'com.android.application' // Uncomment the line if you want to use firebase -// apply plugin: 'com.google.gms.google-services' +apply plugin: 'com.google.gms.google-services' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" @@ -62,7 +62,7 @@ flutter { dependencies { // Uncomment the line if you want to use firebase - // implementation 'com.google.firebase:firebase-analytics:17.2.2' + implementation 'com.google.firebase:firebase-analytics:17.2.2' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" api 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2' diff --git a/android/build.gradle b/android/build.gradle index b27fdb8..7924caa 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -9,7 +9,7 @@ buildscript { classpath 'com.android.tools.build:gradle:3.5.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // Uncomment the line if you want to use firebase - // classpath 'com.google.gms:google-services:4.3.3' + classpath 'com.google.gms:google-services:4.3.3' } } diff --git a/lib/screens/medicine/medicine_recognition_ML_Kit.dart b/lib/screens/medicine/medicine_recognition_ML_Kit.dart index aecb9c8..13e2d0d 100644 --- a/lib/screens/medicine/medicine_recognition_ML_Kit.dart +++ b/lib/screens/medicine/medicine_recognition_ML_Kit.dart @@ -8,6 +8,7 @@ import 'package:flutter/material.dart'; import 'package:getwidget/colors/gf_color.dart'; import 'package:getwidget/components/appbar/gf_appbar.dart'; import 'package:image_picker/image_picker.dart'; +import 'package:modal_progress_hud/modal_progress_hud.dart'; class MedicineRecognitionMLKit extends StatefulWidget { @override @@ -18,6 +19,7 @@ class MedicineRecognitionMLKit extends StatefulWidget { class _MedicineRecognitionMLKitState extends State { var _imageText = []; var _drugList = []; + var _selectedDrugList = []; File image; ImagePicker imagePicker; @@ -27,10 +29,21 @@ class _MedicineRecognitionMLKitState extends State { String format = "json"; String parameter_1 = "drug_name"; + final scaffoldKey1 = new GlobalKey(); + + //decides when to active/inactive spinner indicator + bool showSpinner = false; + + void _showSnackBar(String text) { + scaffoldKey1.currentState + .showSnackBar(new SnackBar(content: new Text(text))); + } + _callAPI(String drugName) async { try { final response = await http .get('$baseURL/$version/$endpoint\.$format?$parameter_1=$drugName'); + print(response); if (response.statusCode == 200) { var data = json.decode(response.body); @@ -40,14 +53,16 @@ class _MedicineRecognitionMLKitState extends State { setState(() { _drugList.add(drugName); }); + return true; } } } } on Exception catch (e) { setState(() { _drugList.clear(); - _drugList.add("No data available"); + showSpinner = false; }); + return false; } } @@ -66,7 +81,8 @@ class _MedicineRecognitionMLKitState extends State { convertImageToText(); }); } on Exception catch (e) { - //print e to snackbar + _showSnackBar("An unexpected error occured."); + print(e); } } @@ -83,9 +99,15 @@ class _MedicineRecognitionMLKitState extends State { File imageNew = File(pickedFile.path); setState(() { image = imageNew; - convertImageToText(); + convertImageToText().whenComplete(() {showSpinner = false; }); + }); } on Exception catch (e) { + setState(() { + showSpinner = false; + }); + _showSnackBar("An unexpected error occured."); + print(e); } } @@ -110,10 +132,17 @@ class _MedicineRecognitionMLKitState extends State { } //remove duplicates _imageText = _imageText.toSet().toList(); + //call the api for (String item in _imageText) { - _callAPI(item); + bool success = _callAPI(item); + if (!success) { + _showSnackBar("Please check your internet connectivity."); + break; + } } + }); + } @override @@ -126,6 +155,7 @@ class _MedicineRecognitionMLKitState extends State { @override Widget build(BuildContext context) { return Scaffold( + key: scaffoldKey1, appBar: GFAppBar( backgroundColor: GFColors.DARK, leading: InkWell( @@ -144,56 +174,361 @@ class _MedicineRecognitionMLKitState extends State { ), centerTitle: true, ), - body: Center( - child: SingleChildScrollView( - child: Padding( - padding: EdgeInsets.all(40.0), - child: (image == null) - ? Icon( - Icons.search, - size: 150, - color: Colors.grey.withOpacity(0.44), - ) - : Column( - children: [ - Text( - "Captured Image", - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w400, - color: Colors.purple), - ), - SizedBox(height: 10.0), - Image.file( - image, - width: 140, - height: 192, - fit: BoxFit.fill, - ), - SizedBox(height: 20.0), - - Text( - "All words found in the image", - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w400, - color: Colors.purple), - ), - SizedBox(height: 10.0), - Text(_imageText.toString()), - SizedBox(height: 20.0), - Text( - "Medicine words", - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w400, - color: Colors.purple), - ), - SizedBox(height: 10.0), - Text(_drugList.toString()), - // (_drugs.isNotEmpty) ? Text(_drugs) : Text("No data available"), - ], - ), + body: ModalProgressHUD( + // color: Colors.purple, + inAsyncCall: showSpinner, + child: Center( + child: SingleChildScrollView( + child: Padding( + padding: EdgeInsets.all(40.0), + child: (image == null) + ? Icon( + Icons.search, + size: 150, + color: Colors.grey.withOpacity(0.44), + ) + : Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Flexible( + child: Text( + "Captured Image", + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Colors.purple), + ), + ), + ], + ), + SizedBox(height: 10.0), + Image.file( + image, + width: 140, + height: 192, + fit: BoxFit.fill, + ), + SizedBox(height: 20.0), + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Flexible( + child: Text( + "All words found in the image", + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Colors.purple), + ), + ), + ], + ), + SizedBox(height: 10.0), + _imageText.length == 0 + ? Container( + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: Text( + "No data available", + style: TextStyle( + fontSize: 10, + fontWeight: FontWeight.w400, + color: Colors.red), + ), + ) + : Container( + height: _imageText.length < 4 + ? 160.0 + : _imageText.length * 40.0, + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: ListView.builder( + shrinkWrap: true, + physics: AlwaysScrollableScrollPhysics(), + itemCount: _imageText.length, + itemBuilder: (context, index) { + return Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + SizedBox(height: 10.0), + RaisedButton( + child: Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + flex: 3, + child: Icon(Icons.add), + ), + Expanded( + flex: 10, + child: + Text(_imageText[index]), + ), + ], + ), + onPressed: () { + setState(() { + final words = + _selectedDrugList + .firstWhere( + (element) => + element == + _imageText[ + index], + orElse: () { + return null; + }); + if (words == null) { + _selectedDrugList + .add(_imageText[index]); + } + }); + }, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all( + Radius.circular(15.0), + ), + ), + ), + ], + ); + }), + ), + SizedBox(height: 20.0), + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Flexible( + child: Text( + "Medicines related keywords", + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Colors.purple), + ), + ), + ], + ), + SizedBox(height: 10.0), + _drugList.length == 0 + ? Container( + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: Text( + "No data available", + style: TextStyle( + fontSize: 10, + fontWeight: FontWeight.w400, + color: Colors.red), + ), + ) + : Container( + height: _drugList.length < 4 + ? 160.0 + : _drugList.length * 40.0, + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: ListView.builder( + shrinkWrap: true, + physics: AlwaysScrollableScrollPhysics(), + itemCount: _drugList.length, + itemBuilder: (context, index) { + return Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + SizedBox(height: 10.0), + RaisedButton( + child: Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + flex: 3, + child: Icon(Icons.add), + ), + Expanded( + flex: 10, + child: + Text(_drugList[index]), + ), + ], + ), + onPressed: () { + setState(() { + final drug = _selectedDrugList + .firstWhere( + (element) => + element == + _drugList[index], + orElse: () { + return null; + }); + if (drug == null) { + _selectedDrugList + .add(_drugList[index]); + } + }); + }, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all( + Radius.circular(15.0), + ), + ), + ), + ], + ); + }), + ), + SizedBox(height: 20.0), + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Flexible( + child: Text( + "Selected Drug List", + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Colors.purple), + ), + ), + ], + ), + SizedBox(height: 10.0), + _selectedDrugList.length == 0 + ? Container( + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: Text( + "No data available", + style: TextStyle( + fontSize: 10, + fontWeight: FontWeight.w400, + color: Colors.red), + ), + ) + : Container( + height: _selectedDrugList.length < 4 + ? 160.0 + : _selectedDrugList.length * 40.0, + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: ListView.builder( + shrinkWrap: true, + physics: AlwaysScrollableScrollPhysics(), + itemCount: _selectedDrugList.length, + itemBuilder: (context, index) { + return Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + SizedBox(height: 10.0), + RaisedButton( + child: Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + flex: 3, + child: Icon(Icons.remove), + ), + Expanded( + flex: 10, + child: Text( + _selectedDrugList[ + index]), + ), + ], + ), + onPressed: () { + setState(() { + _selectedDrugList.remove( + _selectedDrugList[index]); + }); + }, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all( + Radius.circular(15.0), + ), + ), + ), + ], + ); + }), + ), + SizedBox(height: 20.0), + ], + ), + ), ), ), ), @@ -207,6 +542,7 @@ class _MedicineRecognitionMLKitState extends State { heroTag: null, backgroundColor: GFColors.DARK, onPressed: () async { + showSpinner = true; captureFromCamera(); }, child: Icon(Icons.camera), @@ -215,6 +551,7 @@ class _MedicineRecognitionMLKitState extends State { heroTag: null, backgroundColor: GFColors.DARK, onPressed: () async { + showSpinner = true; chooseFromGalery(); }, child: Icon(Icons.file_upload), From 57869dec5effe095026116f14cf5b541903abca3 Mon Sep 17 00:00:00 2001 From: viradhanus Date: Mon, 1 Mar 2021 01:21:14 +0530 Subject: [PATCH 2/4] loading shrimmer added --- .../medicine/medicine_recognition_ML_Kit.dart | 762 ++++++++++-------- lib/utils/wordlistloadingshimmer.dart | 51 ++ 2 files changed, 457 insertions(+), 356 deletions(-) create mode 100644 lib/utils/wordlistloadingshimmer.dart diff --git a/lib/screens/medicine/medicine_recognition_ML_Kit.dart b/lib/screens/medicine/medicine_recognition_ML_Kit.dart index 13e2d0d..401c439 100644 --- a/lib/screens/medicine/medicine_recognition_ML_Kit.dart +++ b/lib/screens/medicine/medicine_recognition_ML_Kit.dart @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; import 'package:getwidget/colors/gf_color.dart'; import 'package:getwidget/components/appbar/gf_appbar.dart'; import 'package:image_picker/image_picker.dart'; -import 'package:modal_progress_hud/modal_progress_hud.dart'; +import 'package:openemr/utils/wordlistloadingshimmer.dart'; class MedicineRecognitionMLKit extends StatefulWidget { @override @@ -19,10 +19,14 @@ class MedicineRecognitionMLKit extends StatefulWidget { class _MedicineRecognitionMLKitState extends State { var _imageText = []; var _drugList = []; + var _temp_drugList = []; var _selectedDrugList = []; File image; ImagePicker imagePicker; + bool _isLoading = false; + bool _isLoadingKeywords = false; + String baseURL = "https://dailymed.nlm.nih.gov/dailymed/services"; String version = "v2"; String endpoint = "drugnames"; @@ -31,14 +35,23 @@ class _MedicineRecognitionMLKitState extends State { final scaffoldKey1 = new GlobalKey(); - //decides when to active/inactive spinner indicator - bool showSpinner = false; - void _showSnackBar(String text) { scaffoldKey1.currentState .showSnackBar(new SnackBar(content: new Text(text))); } + void _toggleLoadingWords(bool newLoadingState) { + setState(() { + _isLoading = newLoadingState; + }); + } + + void _toggleLoadingKeywords(bool newLoadingState) { + setState(() { + _isLoadingKeywords = newLoadingState; + }); + } + _callAPI(String drugName) async { try { final response = await http @@ -53,15 +66,26 @@ class _MedicineRecognitionMLKitState extends State { setState(() { _drugList.add(drugName); }); + + // _toggleLoadingKeywords(false); + return true; + }else{ + return false; + } + }else{ + return false; + } + }else{ + return false; } - } - } } on Exception catch (e) { setState(() { _drugList.clear(); - showSpinner = false; }); + _toggleLoadingKeywords(false); + _showSnackBar("Please check your internet connectivity."); + return false; } } @@ -81,6 +105,8 @@ class _MedicineRecognitionMLKitState extends State { convertImageToText(); }); } on Exception catch (e) { + _toggleLoadingWords(false); + _toggleLoadingKeywords(false); _showSnackBar("An unexpected error occured."); print(e); @@ -99,13 +125,12 @@ class _MedicineRecognitionMLKitState extends State { File imageNew = File(pickedFile.path); setState(() { image = imageNew; - convertImageToText().whenComplete(() {showSpinner = false; }); - + convertImageToText(); }); } on Exception catch (e) { - setState(() { - showSpinner = false; - }); + _toggleLoadingWords(false); + _toggleLoadingKeywords(false); + _showSnackBar("An unexpected error occured."); print(e); @@ -132,17 +157,24 @@ class _MedicineRecognitionMLKitState extends State { } //remove duplicates _imageText = _imageText.toSet().toList(); + _toggleLoadingWords(false); + //call the api for (String item in _imageText) { + // _toggleLoadingKeywords(true); + bool success = _callAPI(item); if (!success) { - _showSnackBar("Please check your internet connectivity."); + _toggleLoadingKeywords(false); break; } } - }); - + setState(() { + // _drugList = _temp_drugList; + _toggleLoadingKeywords(false); + }); + // _toggleLoadingWords(false); } @override @@ -174,363 +206,379 @@ class _MedicineRecognitionMLKitState extends State { ), centerTitle: true, ), - body: ModalProgressHUD( - // color: Colors.purple, - inAsyncCall: showSpinner, - child: Center( - child: SingleChildScrollView( - child: Padding( - padding: EdgeInsets.all(40.0), - child: (image == null) - ? Icon( - Icons.search, - size: 150, - color: Colors.grey.withOpacity(0.44), - ) - : Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Flexible( - child: Text( - "Captured Image", - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w400, - color: Colors.purple), - ), + body: Center( + child: SingleChildScrollView( + child: Padding( + padding: EdgeInsets.all(40.0), + child: (image == null) + ? Icon( + Icons.search, + size: 150, + color: Colors.grey.withOpacity(0.44), + ) + : Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Flexible( + child: Text( + "Captured Image", + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Colors.purple), ), - ], - ), - SizedBox(height: 10.0), - Image.file( - image, - width: 140, - height: 192, - fit: BoxFit.fill, - ), - SizedBox(height: 20.0), - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Flexible( - child: Text( - "All words found in the image", - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w400, - color: Colors.purple), - ), + ), + ], + ), + SizedBox(height: 10.0), + Image.file( + image, + width: 140, + height: 192, + fit: BoxFit.fill, + ), + SizedBox(height: 20.0), + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Flexible( + child: Text( + "All words found in the image", + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Colors.purple), ), - ], - ), - SizedBox(height: 10.0), - _imageText.length == 0 - ? Container( - margin: const EdgeInsets.only( - left: 3.0, right: 3.0, bottom: 5.0), - padding: const EdgeInsets.only( - top: 3.0, - left: 17.0, - right: 17.0, - bottom: 3.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.0), - border: Border.all( - color: Colors.black, width: 1.0)), - child: Text( - "No data available", - style: TextStyle( - fontSize: 10, - fontWeight: FontWeight.w400, - color: Colors.red), - ), - ) - : Container( - height: _imageText.length < 4 - ? 160.0 - : _imageText.length * 40.0, - margin: const EdgeInsets.only( - left: 3.0, right: 3.0, bottom: 5.0), - padding: const EdgeInsets.only( - top: 3.0, - left: 17.0, - right: 17.0, - bottom: 3.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.0), - border: Border.all( - color: Colors.black, width: 1.0)), - child: ListView.builder( - shrinkWrap: true, - physics: AlwaysScrollableScrollPhysics(), - itemCount: _imageText.length, - itemBuilder: (context, index) { - return Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - SizedBox(height: 10.0), - RaisedButton( - child: Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - flex: 3, - child: Icon(Icons.add), - ), - Expanded( - flex: 10, - child: - Text(_imageText[index]), - ), - ], - ), - onPressed: () { - setState(() { - final words = - _selectedDrugList - .firstWhere( - (element) => - element == - _imageText[ - index], - orElse: () { - return null; + ), + ], + ), + SizedBox(height: 10.0), + _isLoading + ? wordListLoadingShimmer(context, + loadingMessage: 'Filtering words', + listLength: 4) + : _imageText.length == 0 + ? Container( + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: + BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: Text( + "No data available", + style: TextStyle( + fontSize: 10, + fontWeight: FontWeight.w400, + color: Colors.red), + ), + ) + : Container( + height: _imageText.length < 4 + ? 160.0 + : _imageText.length * 40.0, + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: + BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: ListView.builder( + shrinkWrap: true, + physics: + AlwaysScrollableScrollPhysics(), + itemCount: _imageText.length, + itemBuilder: (context, index) { + return Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + SizedBox(height: 10.0), + RaisedButton( + child: Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + flex: 3, + child: Icon(Icons.add), + ), + Expanded( + flex: 10, + child: Text( + _imageText[index]), + ), + ], + ), + onPressed: () { + setState(() { + final words = + _selectedDrugList + .firstWhere( + (element) => + element == + _imageText[ + index], + orElse: () { + return null; + }); + if (words == null) { + _selectedDrugList.add( + _imageText[index]); + } }); - if (words == null) { - _selectedDrugList - .add(_imageText[index]); - } - }); - }, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all( - Radius.circular(15.0), + }, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.all( + Radius.circular(15.0), + ), ), ), - ), - ], - ); - }), - ), - SizedBox(height: 20.0), - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Flexible( - child: Text( - "Medicines related keywords", - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.w400, - color: Colors.purple), - ), - ), - ], - ), - SizedBox(height: 10.0), - _drugList.length == 0 - ? Container( - margin: const EdgeInsets.only( - left: 3.0, right: 3.0, bottom: 5.0), - padding: const EdgeInsets.only( - top: 3.0, - left: 17.0, - right: 17.0, - bottom: 3.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.0), - border: Border.all( - color: Colors.black, width: 1.0)), - child: Text( - "No data available", - style: TextStyle( - fontSize: 10, - fontWeight: FontWeight.w400, - color: Colors.red), + ], + ); + }), ), - ) - : Container( - height: _drugList.length < 4 - ? 160.0 - : _drugList.length * 40.0, - margin: const EdgeInsets.only( - left: 3.0, right: 3.0, bottom: 5.0), - padding: const EdgeInsets.only( - top: 3.0, - left: 17.0, - right: 17.0, - bottom: 3.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.0), - border: Border.all( - color: Colors.black, width: 1.0)), - child: ListView.builder( - shrinkWrap: true, - physics: AlwaysScrollableScrollPhysics(), - itemCount: _drugList.length, - itemBuilder: (context, index) { - return Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - SizedBox(height: 10.0), - RaisedButton( - child: Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - flex: 3, - child: Icon(Icons.add), - ), - Expanded( - flex: 10, - child: - Text(_drugList[index]), - ), - ], - ), - onPressed: () { - setState(() { - final drug = _selectedDrugList - .firstWhere( - (element) => - element == - _drugList[index], - orElse: () { - return null; + SizedBox(height: 20.0), + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Flexible( + child: Text( + "Medicines related keywords", + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Colors.purple), + ), + ), + ], + ), + SizedBox(height: 10.0), + // _isLoadingKeywords + // ? wordListLoadingShimmer(context, + // loadingMessage: 'Filtering Keywords', + // listLength: 4) + // : + _drugList.length == 0 + ? Container( + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: + BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: Text( + "No data available", + style: TextStyle( + fontSize: 10, + fontWeight: FontWeight.w400, + color: Colors.red), + ), + ) + : Container( + height: _drugList.length < 4 + ? 160.0 + : _drugList.length * 40.0, + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: + BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: ListView.builder( + shrinkWrap: true, + physics: + AlwaysScrollableScrollPhysics(), + itemCount: _drugList.length, + itemBuilder: (context, index) { + return Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + SizedBox(height: 10.0), + RaisedButton( + child: Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + flex: 3, + child: Icon(Icons.add), + ), + Expanded( + flex: 10, + child: Text( + _drugList[index]), + ), + ], + ), + onPressed: () { + setState(() { + final drug = + _selectedDrugList + .firstWhere( + (element) => + element == + _drugList[ + index], + orElse: () { + return null; + }); + if (drug == null) { + _selectedDrugList.add( + _drugList[index]); + } }); - if (drug == null) { - _selectedDrugList - .add(_drugList[index]); - } - }); - }, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all( - Radius.circular(15.0), + }, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.all( + Radius.circular(15.0), + ), ), ), - ), - ], - ); - }), - ), - SizedBox(height: 20.0), - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Flexible( + ], + ); + }), + ), + SizedBox(height: 20.0), + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Flexible( + child: Text( + "Selected Drug List", + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w400, + color: Colors.purple), + ), + ), + ], + ), + SizedBox(height: 10.0), + _selectedDrugList.length == 0 + ? Container( + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), child: Text( - "Selected Drug List", - overflow: TextOverflow.ellipsis, + "No data available", style: TextStyle( - fontSize: 20, + fontSize: 10, fontWeight: FontWeight.w400, - color: Colors.purple), + color: Colors.red), ), - ), - ], - ), - SizedBox(height: 10.0), - _selectedDrugList.length == 0 - ? Container( - margin: const EdgeInsets.only( - left: 3.0, right: 3.0, bottom: 5.0), - padding: const EdgeInsets.only( - top: 3.0, - left: 17.0, - right: 17.0, - bottom: 3.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.0), - border: Border.all( - color: Colors.black, width: 1.0)), - child: Text( - "No data available", - style: TextStyle( - fontSize: 10, - fontWeight: FontWeight.w400, - color: Colors.red), - ), - ) - : Container( - height: _selectedDrugList.length < 4 - ? 160.0 - : _selectedDrugList.length * 40.0, - margin: const EdgeInsets.only( - left: 3.0, right: 3.0, bottom: 5.0), - padding: const EdgeInsets.only( - top: 3.0, - left: 17.0, - right: 17.0, - bottom: 3.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.0), - border: Border.all( - color: Colors.black, width: 1.0)), - child: ListView.builder( - shrinkWrap: true, - physics: AlwaysScrollableScrollPhysics(), - itemCount: _selectedDrugList.length, - itemBuilder: (context, index) { - return Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - SizedBox(height: 10.0), - RaisedButton( - child: Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - flex: 3, - child: Icon(Icons.remove), - ), - Expanded( - flex: 10, - child: Text( - _selectedDrugList[ - index]), - ), - ], - ), - onPressed: () { - setState(() { - _selectedDrugList.remove( - _selectedDrugList[index]); - }); - }, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all( - Radius.circular(15.0), + ) + : Container( + height: _selectedDrugList.length < 4 + ? 160.0 + : _selectedDrugList.length * 40.0, + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: ListView.builder( + shrinkWrap: true, + physics: AlwaysScrollableScrollPhysics(), + itemCount: _selectedDrugList.length, + itemBuilder: (context, index) { + return Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + SizedBox(height: 10.0), + RaisedButton( + child: Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + flex: 3, + child: Icon(Icons.remove), + ), + Expanded( + flex: 10, + child: Text( + _selectedDrugList[index]), ), + ], + ), + onPressed: () { + setState(() { + _selectedDrugList.remove( + _selectedDrugList[index]); + }); + }, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all( + Radius.circular(15.0), ), ), - ], - ); - }), - ), - SizedBox(height: 20.0), - ], - ), - ), + ), + ], + ); + }), + ), + SizedBox(height: 20.0), + Text(_drugList.toString()) + ], + ), ), ), + // ), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, floatingActionButton: Padding( @@ -542,7 +590,8 @@ class _MedicineRecognitionMLKitState extends State { heroTag: null, backgroundColor: GFColors.DARK, onPressed: () async { - showSpinner = true; + _toggleLoadingWords(true); + _toggleLoadingKeywords(true); captureFromCamera(); }, child: Icon(Icons.camera), @@ -551,7 +600,8 @@ class _MedicineRecognitionMLKitState extends State { heroTag: null, backgroundColor: GFColors.DARK, onPressed: () async { - showSpinner = true; + _toggleLoadingWords(true); + _toggleLoadingKeywords(true); chooseFromGalery(); }, child: Icon(Icons.file_upload), diff --git a/lib/utils/wordlistloadingshimmer.dart b/lib/utils/wordlistloadingshimmer.dart new file mode 100644 index 0000000..8079d12 --- /dev/null +++ b/lib/utils/wordlistloadingshimmer.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; +import 'package:getwidget/components/shimmer/gf_shimmer.dart'; + +Widget listItemShimmer(BuildContext context) { + return GFShimmer( + child: Container( + padding: const EdgeInsets.fromLTRB(10, 5, 5, 5), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + height: 25, + width: MediaQuery.of(context).size.width * 0.55, + color: Colors.white, + ), + SizedBox(height: 10), + Container( + height: 20, + width: MediaQuery.of(context).size.width * 0.5, + color: Colors.white, + ), + ], + ), + ), + ); +} + +Widget wordListLoadingShimmer(BuildContext context, + {String loadingMessage, int listLength = 1}) { + return Container( + alignment: Alignment.center, + width: MediaQuery.of(context).size.width * 0.8, + margin: const EdgeInsets.symmetric(vertical: 10), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + loadingMessage == null + ? Container() + : Padding( + padding: const EdgeInsets.only(bottom: 10), + child: Text( + loadingMessage, + style: TextStyle(fontSize: 16, color: Colors.grey), + ), + ), + for (var i = 0; i < listLength; i++) listItemShimmer(context) + ], + ), + ); +} From 741a8cc523053a969c6375a45481f1b32760c5cc Mon Sep 17 00:00:00 2001 From: viradhanus Date: Mon, 1 Mar 2021 19:27:44 +0530 Subject: [PATCH 3/4] api check 1 --- .../medicine/medicine_recognition_ML_Kit.dart | 264 +++++++++--------- 1 file changed, 132 insertions(+), 132 deletions(-) diff --git a/lib/screens/medicine/medicine_recognition_ML_Kit.dart b/lib/screens/medicine/medicine_recognition_ML_Kit.dart index 401c439..6e399c5 100644 --- a/lib/screens/medicine/medicine_recognition_ML_Kit.dart +++ b/lib/screens/medicine/medicine_recognition_ML_Kit.dart @@ -52,44 +52,6 @@ class _MedicineRecognitionMLKitState extends State { }); } - _callAPI(String drugName) async { - try { - final response = await http - .get('$baseURL/$version/$endpoint\.$format?$parameter_1=$drugName'); - - print(response); - if (response.statusCode == 200) { - var data = json.decode(response.body); - if (data.isNotEmpty) { - int drugCount = data["metadata"]["total_elements"]; - if (drugCount > 0) { - setState(() { - _drugList.add(drugName); - }); - - // _toggleLoadingKeywords(false); - - return true; - }else{ - return false; - } - }else{ - return false; - } - }else{ - return false; - } - } on Exception catch (e) { - setState(() { - _drugList.clear(); - }); - _toggleLoadingKeywords(false); - _showSnackBar("Please check your internet connectivity."); - - return false; - } - } - captureFromCamera() async { setState(() { image = null; @@ -163,6 +125,7 @@ class _MedicineRecognitionMLKitState extends State { for (String item in _imageText) { // _toggleLoadingKeywords(true); + bool success = _callAPI(item); if (!success) { _toggleLoadingKeywords(false); @@ -177,6 +140,50 @@ class _MedicineRecognitionMLKitState extends State { // _toggleLoadingWords(false); } + _callAPI(String drugName) async { + try { + final response = await http.get( + '$baseURL/$version/$endpoint\.$format?$parameter_1=$drugName'); + // 'https://rxnav.nlm.nih.gov/drugs/zPrescribe/rxcui.json?name=$drugName'); + + print(response); + if (response.statusCode == 200) { + setState(() { + + _drugList.add(drugName); + }); + + var data = json.decode(response.body); + if (data.isNotEmpty) { + int drugCount = data["metadata"]["total_elements"]; + if (drugCount > 0) { + setState(() { + // _drugList.add(drugName); + }); + + // _toggleLoadingKeywords(false); + + return true; + } else { + return false; + } + } else { + return false; + } + } else { + return false; + } + } on Exception catch (e) { + setState(() { + _drugList.clear(); + }); + _toggleLoadingKeywords(false); + _showSnackBar("Please check your internet connectivity."); + + return false; + } + } + @override void initState() { super.initState(); @@ -378,103 +385,96 @@ class _MedicineRecognitionMLKitState extends State { // ? wordListLoadingShimmer(context, // loadingMessage: 'Filtering Keywords', // listLength: 4) - // : - _drugList.length == 0 - ? Container( - margin: const EdgeInsets.only( - left: 3.0, right: 3.0, bottom: 5.0), - padding: const EdgeInsets.only( - top: 3.0, - left: 17.0, - right: 17.0, - bottom: 3.0), - decoration: BoxDecoration( - borderRadius: - BorderRadius.circular(15.0), - border: Border.all( - color: Colors.black, width: 1.0)), - child: Text( - "No data available", - style: TextStyle( - fontSize: 10, - fontWeight: FontWeight.w400, - color: Colors.red), - ), - ) - : Container( - height: _drugList.length < 4 - ? 160.0 - : _drugList.length * 40.0, - margin: const EdgeInsets.only( - left: 3.0, right: 3.0, bottom: 5.0), - padding: const EdgeInsets.only( - top: 3.0, - left: 17.0, - right: 17.0, - bottom: 3.0), - decoration: BoxDecoration( - borderRadius: - BorderRadius.circular(15.0), - border: Border.all( - color: Colors.black, width: 1.0)), - child: ListView.builder( - shrinkWrap: true, - physics: - AlwaysScrollableScrollPhysics(), - itemCount: _drugList.length, - itemBuilder: (context, index) { - return Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - SizedBox(height: 10.0), - RaisedButton( - child: Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - flex: 3, - child: Icon(Icons.add), - ), - Expanded( - flex: 10, - child: Text( - _drugList[index]), - ), - ], + // : + _drugList.length == 0 + ? Container( + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: Text( + "No data available", + style: TextStyle( + fontSize: 10, + fontWeight: FontWeight.w400, + color: Colors.red), + ), + ) + : Container( + height: _drugList.length < 4 + ? 160.0 + : _drugList.length * 40.0, + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: ListView.builder( + shrinkWrap: true, + physics: AlwaysScrollableScrollPhysics(), + itemCount: _drugList.length, + itemBuilder: (context, index) { + return Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + SizedBox(height: 10.0), + RaisedButton( + child: Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + flex: 3, + child: Icon(Icons.add), ), - onPressed: () { - setState(() { - final drug = - _selectedDrugList - .firstWhere( - (element) => - element == - _drugList[ - index], - orElse: () { - return null; - }); - if (drug == null) { - _selectedDrugList.add( - _drugList[index]); - } - }); - }, - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.all( - Radius.circular(15.0), - ), + Expanded( + flex: 10, + child: Text(_drugList[index]), ), + ], + ), + onPressed: () { + setState(() { + final drug = _selectedDrugList + .firstWhere( + (element) => + element == + _drugList[index], + orElse: () { + return null; + }); + if (drug == null) { + _selectedDrugList + .add(_drugList[index]); + } + }); + }, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all( + Radius.circular(15.0), ), - ], - ); - }), - ), + ), + ), + ], + ); + }), + ), SizedBox(height: 20.0), Row( mainAxisAlignment: MainAxisAlignment.start, From b09b8e5c96bf05cbc6c710a91e09eba4732eeedf Mon Sep 17 00:00:00 2001 From: viradhanus Date: Tue, 2 Mar 2021 01:03:01 +0530 Subject: [PATCH 4/4] ui improved --- .../medicine/medicine_recognition_ML_Kit.dart | 277 +++++++++--------- 1 file changed, 139 insertions(+), 138 deletions(-) diff --git a/lib/screens/medicine/medicine_recognition_ML_Kit.dart b/lib/screens/medicine/medicine_recognition_ML_Kit.dart index 6e399c5..180f8f6 100644 --- a/lib/screens/medicine/medicine_recognition_ML_Kit.dart +++ b/lib/screens/medicine/medicine_recognition_ML_Kit.dart @@ -19,13 +19,14 @@ class MedicineRecognitionMLKit extends StatefulWidget { class _MedicineRecognitionMLKitState extends State { var _imageText = []; var _drugList = []; - var _temp_drugList = []; var _selectedDrugList = []; File image; ImagePicker imagePicker; bool _isLoading = false; bool _isLoadingKeywords = false; + bool _isLoadingImage = false; + bool _isBtnNotPressed = true; String baseURL = "https://dailymed.nlm.nih.gov/dailymed/services"; String version = "v2"; @@ -52,6 +53,17 @@ class _MedicineRecognitionMLKitState extends State { }); } + void _toggleLoadingImage(bool newLoadingState) { + setState(() { + _isLoadingImage = newLoadingState; + }); + } + + void _toggleButtonNotPress(bool newLoadingState) { + setState(() { + _isBtnNotPressed = newLoadingState; + }); + } captureFromCamera() async { setState(() { image = null; @@ -63,12 +75,15 @@ class _MedicineRecognitionMLKitState extends State { await imagePicker.getImage(source: ImageSource.camera); File imageNew = File(pickedFile.path); setState(() { + _toggleLoadingImage(false); image = imageNew; convertImageToText(); }); } on Exception catch (e) { _toggleLoadingWords(false); _toggleLoadingKeywords(false); + _toggleLoadingImage(false); + _showSnackBar("An unexpected error occured."); print(e); @@ -86,12 +101,14 @@ class _MedicineRecognitionMLKitState extends State { await imagePicker.getImage(source: ImageSource.gallery); File imageNew = File(pickedFile.path); setState(() { + _toggleLoadingImage(false); image = imageNew; convertImageToText(); }); } on Exception catch (e) { _toggleLoadingWords(false); _toggleLoadingKeywords(false); + _toggleLoadingImage(false); _showSnackBar("An unexpected error occured."); @@ -122,65 +139,37 @@ class _MedicineRecognitionMLKitState extends State { _toggleLoadingWords(false); //call the api + int count = 1; for (String item in _imageText) { - // _toggleLoadingKeywords(true); - - - bool success = _callAPI(item); - if (!success) { - _toggleLoadingKeywords(false); - break; - } + _callAPI(item); } }); - setState(() { - // _drugList = _temp_drugList; - _toggleLoadingKeywords(false); - }); - // _toggleLoadingWords(false); } _callAPI(String drugName) async { try { - final response = await http.get( - '$baseURL/$version/$endpoint\.$format?$parameter_1=$drugName'); - // 'https://rxnav.nlm.nih.gov/drugs/zPrescribe/rxcui.json?name=$drugName'); - + final response = await http + .get('$baseURL/$version/$endpoint\.$format?$parameter_1=$drugName'); print(response); + if (drugName == _imageText[_imageText.length - 1]) { + _toggleLoadingKeywords(false); + } if (response.statusCode == 200) { - setState(() { - - _drugList.add(drugName); - }); - var data = json.decode(response.body); if (data.isNotEmpty) { int drugCount = data["metadata"]["total_elements"]; if (drugCount > 0) { setState(() { - // _drugList.add(drugName); + _drugList.add(drugName); }); - - // _toggleLoadingKeywords(false); - - return true; - } else { - return false; } - } else { - return false; } - } else { - return false; } } on Exception catch (e) { setState(() { _drugList.clear(); }); _toggleLoadingKeywords(false); - _showSnackBar("Please check your internet connectivity."); - - return false; } } @@ -217,7 +206,7 @@ class _MedicineRecognitionMLKitState extends State { child: SingleChildScrollView( child: Padding( padding: EdgeInsets.all(40.0), - child: (image == null) + child: (image == null && _isBtnNotPressed) ? Icon( Icons.search, size: 150, @@ -241,12 +230,16 @@ class _MedicineRecognitionMLKitState extends State { ], ), SizedBox(height: 10.0), - Image.file( - image, - width: 140, - height: 192, - fit: BoxFit.fill, - ), + _isLoadingImage + ? wordListLoadingShimmer(context, + loadingMessage: 'Getting the image', + listLength: 2) + : Image.file( + image, + width: 140, + height: 192, + fit: BoxFit.fill, + ), SizedBox(height: 20.0), Row( mainAxisAlignment: MainAxisAlignment.start, @@ -381,100 +374,106 @@ class _MedicineRecognitionMLKitState extends State { ], ), SizedBox(height: 10.0), - // _isLoadingKeywords - // ? wordListLoadingShimmer(context, - // loadingMessage: 'Filtering Keywords', - // listLength: 4) - // : - _drugList.length == 0 - ? Container( - margin: const EdgeInsets.only( - left: 3.0, right: 3.0, bottom: 5.0), - padding: const EdgeInsets.only( - top: 3.0, - left: 17.0, - right: 17.0, - bottom: 3.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.0), - border: Border.all( - color: Colors.black, width: 1.0)), - child: Text( - "No data available", - style: TextStyle( - fontSize: 10, - fontWeight: FontWeight.w400, - color: Colors.red), - ), - ) - : Container( - height: _drugList.length < 4 - ? 160.0 - : _drugList.length * 40.0, - margin: const EdgeInsets.only( - left: 3.0, right: 3.0, bottom: 5.0), - padding: const EdgeInsets.only( - top: 3.0, - left: 17.0, - right: 17.0, - bottom: 3.0), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15.0), - border: Border.all( - color: Colors.black, width: 1.0)), - child: ListView.builder( - shrinkWrap: true, - physics: AlwaysScrollableScrollPhysics(), - itemCount: _drugList.length, - itemBuilder: (context, index) { - return Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - SizedBox(height: 10.0), - RaisedButton( - child: Row( - mainAxisAlignment: - MainAxisAlignment.center, - children: [ - Expanded( - flex: 3, - child: Icon(Icons.add), + _isLoadingKeywords + ? wordListLoadingShimmer(context, + loadingMessage: 'Filtering Keywords', + listLength: 4) + : _drugList.length == 0 + ? Container( + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: + BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: Text( + "No data available", + style: TextStyle( + fontSize: 10, + fontWeight: FontWeight.w400, + color: Colors.red), + ), + ) + : Container( + height: _drugList.length < 4 + ? 160.0 + : _drugList.length * 40.0, + margin: const EdgeInsets.only( + left: 3.0, right: 3.0, bottom: 5.0), + padding: const EdgeInsets.only( + top: 3.0, + left: 17.0, + right: 17.0, + bottom: 3.0), + decoration: BoxDecoration( + borderRadius: + BorderRadius.circular(15.0), + border: Border.all( + color: Colors.black, width: 1.0)), + child: ListView.builder( + shrinkWrap: true, + physics: + AlwaysScrollableScrollPhysics(), + itemCount: _drugList.length, + itemBuilder: (context, index) { + return Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + SizedBox(height: 10.0), + RaisedButton( + child: Row( + mainAxisAlignment: + MainAxisAlignment.center, + children: [ + Expanded( + flex: 3, + child: Icon(Icons.add), + ), + Expanded( + flex: 10, + child: Text( + _drugList[index]), + ), + ], ), - Expanded( - flex: 10, - child: Text(_drugList[index]), + onPressed: () { + setState(() { + final drug = + _selectedDrugList + .firstWhere( + (element) => + element == + _drugList[ + index], + orElse: () { + return null; + }); + if (drug == null) { + _selectedDrugList.add( + _drugList[index]); + } + }); + }, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.all( + Radius.circular(15.0), + ), ), - ], - ), - onPressed: () { - setState(() { - final drug = _selectedDrugList - .firstWhere( - (element) => - element == - _drugList[index], - orElse: () { - return null; - }); - if (drug == null) { - _selectedDrugList - .add(_drugList[index]); - } - }); - }, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all( - Radius.circular(15.0), ), - ), - ), - ], - ); - }), - ), + ], + ); + }), + ), SizedBox(height: 20.0), Row( mainAxisAlignment: MainAxisAlignment.start, @@ -506,7 +505,7 @@ class _MedicineRecognitionMLKitState extends State { border: Border.all( color: Colors.black, width: 1.0)), child: Text( - "No data available", + "No selected madicine found", style: TextStyle( fontSize: 10, fontWeight: FontWeight.w400, @@ -573,12 +572,10 @@ class _MedicineRecognitionMLKitState extends State { }), ), SizedBox(height: 20.0), - Text(_drugList.toString()) ], ), ), ), - // ), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, floatingActionButton: Padding( @@ -592,6 +589,8 @@ class _MedicineRecognitionMLKitState extends State { onPressed: () async { _toggleLoadingWords(true); _toggleLoadingKeywords(true); + _toggleLoadingImage(true); + _toggleButtonNotPress(false); captureFromCamera(); }, child: Icon(Icons.camera), @@ -602,6 +601,8 @@ class _MedicineRecognitionMLKitState extends State { onPressed: () async { _toggleLoadingWords(true); _toggleLoadingKeywords(true); + _toggleLoadingImage(true); + _toggleButtonNotPress(false); chooseFromGalery(); }, child: Icon(Icons.file_upload),