Skip to content

Commit

Permalink
Added calling feature along with text recognition
Browse files Browse the repository at this point in the history
  • Loading branch information
im-Amitto committed Aug 17, 2020
1 parent c32895d commit 93d99d2
Show file tree
Hide file tree
Showing 15 changed files with 1,122 additions and 287 deletions.
Binary file added flutter_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:openemr/screens/home.dart';
// import './screens/home.dart';

void main() => runApp(MyApp());
void main(){
HttpOverrides.global = new MyHttpOverrides();
runApp(new MyApp());
}

class MyApp extends StatelessWidget {
@override
Expand All @@ -15,3 +19,11 @@ class MyApp extends StatelessWidget {
home: HomePage(),
);
}

class MyHttpOverrides extends HttpOverrides{
@override
HttpClient createHttpClient(SecurityContext context){
return super.createHttpClient(context)
..badCertificateCallback = (X509Certificate cert, String host, int port)=> true;
}
}
29 changes: 2 additions & 27 deletions lib/screens/drawer/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,31 +79,6 @@ class _DrawerPageState extends State<DrawerPage> {
color: Colors.white,
child: Column(
children: <Widget>[
const Padding(
padding: EdgeInsets.only(left: 2),
child: GFListTile(
avatar: Icon(
Icons.error,
color: GFColors.DANGER,
),
title: Text('Webapp Connection',
style:
TextStyle(fontSize: 16, color: Colors.black87)),
),
),
const Padding(
padding: EdgeInsets.only(left: 2),
child: GFListTile(
avatar: Icon(
Icons.error,
color: GFColors.DANGER,
),
title: Text('Firebase Connection',
style:
TextStyle(fontSize: 16, color: Colors.black87)),
),
),
Divider(color: GFColors.FOCUS, indent: 20, endIndent: 30),
InkWell(
onTap: () {
Navigator.push(
Expand Down Expand Up @@ -148,11 +123,11 @@ class _DrawerPageState extends State<DrawerPage> {
Divider(color: GFColors.FOCUS, indent: 20, endIndent: 30),
const Padding(
padding: EdgeInsets.only(left: 2),
child: Text("Last update: 08/12/20"),
child: Text("Last update: 08/18/20"),
),
const Padding(
padding: EdgeInsets.only(left: 2),
child: Text("v2.0"),
child: Text("v2.1"),
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class _HomePageState extends State<HomePage> {
'failRoute': LoginScreen()
},
{
'icon': Icons.info,
'title': 'Medicine',
'icon': Icons.translate,
'title': 'Text Recognition',
'route': MedicineRecognitionPage()
},
{'icon': Icons.scanner, 'title': 'Code scanner', 'route': CodeScanner()},
Expand Down
165 changes: 141 additions & 24 deletions lib/screens/medicine/medicine_recognition.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import 'package:flutter/material.dart';
import 'package:getwidget/getwidget.dart';
import 'package:flutter/cupertino.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import 'package:openemr/utils/rest_ds.dart';
import 'package:openemr/utils/system_padding.dart';
import 'package:shared_preferences/shared_preferences.dart';

class MedicineRecognitionPage extends StatefulWidget {
@override
Expand All @@ -9,38 +14,128 @@ class MedicineRecognitionPage extends StatefulWidget {
}

class _MedicineRecognitionPageState extends State<MedicineRecognitionPage> {
String _result = "";
String serverIP = "";
String tempIP = "";
final scaffoldKey = new GlobalKey<ScaffoldState>();
@override
void initState() {
_loadIp();
super.initState();
}

_loadIp() async {
final prefs = await SharedPreferences.getInstance();
serverIP =
prefs.getString("webrtcIP") == null ? "" : prefs.getString("webrtcIP");
}

_translateImage(File img) async {
if (serverIP == null || serverIP == "") {
_showSnackBar("Please set IP using setting button on top right");
} else {
RestDatasource api = new RestDatasource();
var result = await api.textRecognition(img, serverIP);
print(result);
if (result["err"] != null) {
_showSnackBar(result["err"].toString());
} else {
this.setState(() {
_result = result["data"];
});
}
}
}

_showSnackBar(String text) {
scaffoldKey.currentState
.showSnackBar(new SnackBar(content: new Text(text)));
}

_updateServerIp() async {
await showDialog<String>(
context: context,
child: new SystemPadding(
child: new AlertDialog(
contentPadding: const EdgeInsets.all(16.0),
content: new Row(
children: <Widget>[
new Expanded(
child: new TextField(
onChanged: (value) {
this.setState(() {
tempIP = value;
});
},
autofocus: true,
decoration: new InputDecoration(
labelText: 'Server IP', hintText: 'eg. 10.0.0.1'),
),
),
],
),
actions: <Widget>[
new FlatButton(
child: const Text('CANCEL'),
onPressed: () {
Navigator.pop(context);
}),
new FlatButton(
child: const Text('Update'),
onPressed: () async {
final prefs = await SharedPreferences.getInstance();
prefs.setString("webrtcIP", tempIP);
Navigator.pushNamedAndRemoveUntil(context, '/', (_) => false);
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
MedicineRecognitionPage()),
);
})
],
),
),
);
}

bool fav = false;
@override
Widget build(BuildContext context) => Scaffold(
key: scaffoldKey,
appBar: GFAppBar(
backgroundColor: GFColors.DARK,
leading: InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
child: Icon(
CupertinoIcons.back,
color: GFColors.SUCCESS,
),
)),
title: const Text(
'Medicine Recognition',
style: TextStyle(fontSize: 17),
),
centerTitle: true,
),
backgroundColor: GFColors.DARK,
leading: InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
child: Icon(
CupertinoIcons.back,
color: GFColors.SUCCESS,
),
)),
title: const Text(
'Text Recognition',
style: TextStyle(fontSize: 17),
),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.settings),
tooltip: "Logout",
color: GFColors.DANGER,
onPressed: () => _updateServerIp(),
),
]),
body: Center(
child: Icon(
Icons.search,
size: 150,
color: Colors.grey.withOpacity(0.44),
),
child: (_result == null || _result == "")
? Icon(
Icons.search,
size: 150,
color: Colors.grey.withOpacity(0.44),
)
: Text(_result),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
floatingActionButton: Padding(
Expand All @@ -51,13 +146,35 @@ class _MedicineRecognitionPageState extends State<MedicineRecognitionPage> {
FloatingActionButton(
heroTag: null,
backgroundColor: GFColors.DARK,
onPressed: () {},
onPressed: () async {
File result = await ImagePicker.pickImage(
source: ImageSource.camera,
imageQuality: 80,
maxHeight: 400,
maxWidth: 400,
);

if (result != null) {
_translateImage(result);
}
},
child: Icon(Icons.camera),
),
FloatingActionButton(
heroTag: null,
backgroundColor: GFColors.DARK,
onPressed: () {},
onPressed: () async {
File result = await ImagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 80,
maxHeight: 400,
maxWidth: 400,
);

if (result != null) {
_translateImage(result);
}
},
child: Icon(Icons.file_upload),
)
],
Expand Down
12 changes: 1 addition & 11 deletions lib/screens/telehealth/chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,7 @@ class _ChatScreenState extends State<ChatScreen> {
widget.heading,
style: TextStyle(fontSize: 17),
),
centerTitle: true,
actions: <Widget>[
GFIconButton(
icon: Icon(
Icons.call,
color: Colors.blue,
),
onPressed: () {},
type: GFButtonType.transparent,
),
]),
centerTitle: true,),
body: StreamBuilder(
stream: Firestore.instance
.collection('messages')
Expand Down
Loading

0 comments on commit 93d99d2

Please sign in to comment.