Reputation: 19
I am trying to build and install the app created in android studio using flutter, but while installing I am getting this error and the app is not running. on the mobile phone I'm getting the error " Unimplemented error" How to resolve this error?
import 'package:flutter/material.dart';
import 'package:camera/camera.dart';
import 'package:flutter/services.dart';
import 'package:tflite/tflite.dart';
import 'dart:async';
//import 'lib.dart';
import 'main.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage>
{
late CameraController cameraController;
//defining variables
late CameraImage imgCamera;
bool isWorking=false;
late double imgHeight;
late double imgWidth;
late List recognitionsList;
initCamera()
{
cameraController=CameraController(cameras[0],ResolutionPreset.medium);
cameraController.initialize().then((value)
{
if(!mounted)
{
return;
}
setState(()
{
cameraController.startImageStream((imageFromStream)=>
{
if(!isWorking)
{
isWorking=true,
imgCamera= imageFromStream,
runModelOnStreamFrame(),
}
});
});
});
}
runModelOnStreamFrame() async {
imgHeight = imgCamera.height + 0.0;
imgWidth=imgCamera.width + 0.0;
recognitionsList= (await Tflite.detectObjectOnFrame(bytesList:imgCamera.planes.map((plane){
return plane.bytes;
}).toList() ,
model:"SSDMobileNet", //change it to other name assets/ssd_mobilenet.tflite
imageHeight: imgCamera.height,
imageWidth: imgCamera.width,
imageMean: 127.5,
imageStd: 127.5,
numResultsPerClass: 1,
threshold: 0.4,
))!;
isWorking=false;
setState(()
{
imgCamera;
});
Future <dynamic> loadModel() async
{
Tflite.close();
try{
late String response;
response = (await Tflite.loadModel(
model:"assets/ssd_mobilenet.tflite",
labels: "assets/ssd_mobilenet.txt"
))!;
print(response);
}
// catch{}
on PlatformException
{
print("unable to load model");
}
}
@override
void dispose()
{
super.dispose();
cameraController.stopImageStream();
Tflite.close();
}
@override
void initState()
{
super.initState();
initCamera();
}
List<Widget> displayBoxesAroundRecognizedObjects(Size screen)
{
if(recognitionsList == null) return[];
if(imgHeight == null || imgWidth == null) return[];
double factorX = screen.width;
double factorY = imgHeight;
Color colorPick = Colors.lightGreenAccent;
return recognitionsList.map((result)
{
return Positioned(
left:result["rect"]["x"] * factorX,
top:result["rect"]["y"] * factorY,
width:result["rect"]["w"] * factorX,
height:result["rect"]["h"] * factorY,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
border: Border.all(color:Colors.lightGreenAccent,width:2.0),
),
child:Text(
"${result['detectedClass']} ${(result['confidenceInClass'] * 100).toStringAsFixed(0)}%",
style:TextStyle(
background:Paint()..color= colorPick,
color:Colors.black,
fontSize:16.0,
),
),
),
);
}).toList();
}
@override
Widget build(BuildContext context)
{
Size size = MediaQuery.of(context).size;
List<Widget> stackChildrenWidgets =[];
stackChildrenWidgets.add(
Positioned(
top: 0.0,
left : 0.0,
width:size.width,height:size.height-100,
child:Container(
height:size.height-100,
child:(!cameraController.value.isInitialized)
? new Container()
: AspectRatio(
aspectRatio: cameraController.value.aspectRatio,
child: CameraPreview(cameraController),
),
),
),
);
if(imgCamera != null)
{
stackChildrenWidgets.addAll(displayBoxesAroundRecognizedObjects(size));
}
return SafeArea(
child: Scaffold
(
backgroundColor: Colors.black,
body: Container(
margin : EdgeInsets.only(top:50),
color:Colors.black,
child:Stack(
children:stackChildrenWidgets,
),
),
),
);
}
}
@override
Widget build(BuildContext context) {
// TODO: implement build
throw UnimplementedError();
}}
======== Exception caught by widgets library ======== The following UnimplementedError was thrown building HomePage(dirty, state: _HomePageState#f3ad6): UnimplementedError
The relevant error-causing widget was: HomePage file:///C:/Users/Vedika/AndroidStudioProjects/object_detection_app/lib/main.dart:20:13 When the exception was thrown, this was the stack: #0 _HomePageState.build (package:object_detection_app/HomePage.dart:195:5) #1 StatefulElement.build (package:flutter/src/widgets/framework.dart:4691:27) #2 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4574:15) #3 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4746:11) #4 Element.rebuild (package:flutter/src/widgets/framework.dart:4267:5)
Upvotes: 0
Views: 1288
Reputation: 660
you just having Unimplemented Error because you throw it in the last peace of code
@override
Widget build(BuildContext context) {
// TODO: implement build
throw UnimplementedError();
}}
please check the code above
Upvotes: 2