From f56921951f4984f918a609f4f90d35d9d59305ce Mon Sep 17 00:00:00 2001 From: Aman-Pinjara Date: Sat, 29 Apr 2023 07:16:18 +0530 Subject: [PATCH] small fix --- lib/Model/prediction.dart | 2 -- lib/Pages/input.dart | 25 ++++++++++++++++++++----- lib/Pages/prediction.dart | 5 ++++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/Model/prediction.dart b/lib/Model/prediction.dart index f0ef89e..5afb1ee 100644 --- a/lib/Model/prediction.dart +++ b/lib/Model/prediction.dart @@ -1,5 +1,3 @@ -import 'dart:ffi'; - class PredictionModel { final int prediction; final Map data; diff --git a/lib/Pages/input.dart b/lib/Pages/input.dart index 0069517..e5b23ba 100644 --- a/lib/Pages/input.dart +++ b/lib/Pages/input.dart @@ -15,6 +15,17 @@ class _InputPageState extends State { late TextEditingController _mchcontroller; late TextEditingController _mchccontroller; late TextEditingController _mcvcontroller; + final _focusNode1 = FocusNode(); + final _focusNode2 = FocusNode(); + final _focusNode3 = FocusNode(); + final _focusNode4 = FocusNode(); + + void unfocus() { + _focusNode1.unfocus(); + _focusNode2.unfocus(); + _focusNode3.unfocus(); + _focusNode4.unfocus(); + } @override void initState() { @@ -89,10 +100,10 @@ class _InputPageState extends State { ], ), ), - myTextField(_hemocontroller, 'Hemoglobin'), - myTextField(_mchcontroller, 'MCH'), - myTextField(_mchccontroller, 'MCHC'), - myTextField(_mcvcontroller, 'MCV'), + myTextField(_hemocontroller, 'Hemoglobin', _focusNode1), + myTextField(_mchcontroller, 'MCH', _focusNode2), + myTextField(_mchccontroller, 'MCHC', _focusNode3), + myTextField(_mcvcontroller, 'MCV', done: true, _focusNode4), SizedBox(height: 50), ElevatedButton( style: ButtonStyle( @@ -101,6 +112,7 @@ class _InputPageState extends State { backgroundColor: MaterialStateProperty.all(Colors.blueAccent), ), onPressed: () { + unfocus(); Navigator.push( context, MaterialPageRoute( @@ -125,11 +137,14 @@ class _InputPageState extends State { ); } - Widget myTextField(TextEditingController controller, String hint, + Widget myTextField( + TextEditingController controller, String hint, FocusNode focusnode, {bool done = false}) { return Padding( padding: const EdgeInsets.all(12.0), child: TextFormField( + focusNode: focusnode, + keyboardType: TextInputType.number, textInputAction: done ? TextInputAction.done : TextInputAction.next, controller: controller, decoration: InputDecoration( diff --git a/lib/Pages/prediction.dart b/lib/Pages/prediction.dart index 4ff0d7c..3589bbd 100644 --- a/lib/Pages/prediction.dart +++ b/lib/Pages/prediction.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'package:diseaseapp/Model/prediction.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:http_parser/http_parser.dart'; class PredictionPage extends StatefulWidget { @@ -38,16 +39,18 @@ class _PredictionPageState extends State { final response = await req.send(); if (response.statusCode == 200) { final res = json.decode(await response.stream.bytesToString()); + Fluttertoast.showToast(msg: "Success"); print("Success"); print(res); return PredictionModel.fromJson(res); } else { + Fluttertoast.showToast(msg: "API Failed", backgroundColor: Colors.red); print("Failed"); } return PredictionModel( prediction: 1, data: { - "MCV":"100", + "MCV": "100", }, ); // return await Future.delayed(const Duration(seconds: 5), () {