Flutter - Android App Shows Just A Blank Screen
Android app shows just a blank screen. Below is my code import 'package:flutter/material.dart'; import 'package:camera/camera.dart'; import 'screens/home_screen.dart'; Future<
Solution 1:
You have to define a route to your HomePage
like this
runApp(
MaterialApp(
title: 'DEMO',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(
title: 'DEMO',
camera: camera,
),
routes: {
HomePage.routeName: (ctx) => HomePage(),
},
),
);
}
then in your home page widget
classHomePageextendsStatefulWidget {
staticconstrouteName='homePage';
Let me know if you need anything else
Solution 2:
I just fixed it.
import'package:flutter/material.dart';
import'package:camera/camera.dart';
import'screens/home_screen.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
finalcameras= await availableCameras();
finalcamera= cameras.first;
runApp(MaterialApp(
title: 'OCR Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(
title: 'OCR Text Recognition',
camera: camera,
),
));
}
Solution 3:
You should request permissions before calling on availableCameras. That's why the screen is blank. Below is my code for using Camera. Get permissions before you call availableCameras. Also go to your android manifest file in flutter app and add the permissions there as well.
import 'package:permission_handler/permission_handler.dart';
@override
voidinitState() {
super.initState();
getPermissions();
}
Future getPermissions() async {
Map<Permission, PermissionStatus> permissions =
await [
Permission.storage, Permission.camera, Permission.microphone
].request();
if (permissions[Permission.storage] == PermissionStatus.granted &&
permissions[Permission.camera] == PermissionStatus.granted &&
permissions[Permission.microphone] == PermissionStatus.granted) {
await getCameras();
}
}
Future getCameras() async {
cameras = await availableCameras();
controller = CameraController(cameras[0], ResolutionPreset.high);
controller.initialize().then((_) {
/*if (!mounted) {
return;
}
setState(() {});*/
setState(() {
isPermitted = true;
});
});
}
Post a Comment for "Flutter - Android App Shows Just A Blank Screen"