I have a problem in intergrating a simple GoogleMap in my Flutter App.
I correctly inserted the API Key in my Manifest file and inserted the library in the app.
But the emulator is just showing a blank page. I am doing nothing special until now; just trying to create a GoogleMap.
This is the Code i am using in the App:
return Stack(
children: <Widget>[
GoogleMap(initialCameraPosition: CameraPosition(target:
LatLng(-33.870840,151.206286),
zoom: 12)
)
], );
What the emulator is showing:
The first lines in the console(which i think are of special meaning):
E/flutter ( 5736): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create a platform view of unregistered type: plugins.flutter.io/google_maps
I tried several workarounds but only ended up with more errors. Looking Forward to your answers!
I tried to add Google Map in a fresh project and was able to see it on emulator successfully. I followed this article step by step and used your code snippet to show the map and it worked.
Complete code used:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Completer<GoogleMapController> _controller = Completer();
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Maps Sample App'),
backgroundColor: Colors.green[700],
),
body: Stack(
children: <Widget>[
GoogleMap(initialCameraPosition: CameraPosition(target:
LatLng(-33.870840,151.206286),
zoom: 12)
)
],
)
),
);
}
}
Couple of points to note:
Double check if the api is enabled (Maps SDK for Android) when you generated key for it.
Do flutter clean once you cross-check to confirm you've latest dependencies.
Hope this helps.
Related
Im using Getx for state management. I'm getting an error when I use getx set method.
I am using this code for Getx class:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
// Bu alan benim sayac değişkenlerimi Getx yardımı ile tuttuğum classdır.farkllı değişken classları yazılabilir.
class SayacController extends GetxController {
//5 benim değikenimin ilk değeridir.
var _sayac = 5.obs;
//get ile çeker, set ile veriyi atarım.
get sayac => _sayac.value;
set sayac(yeniDeger) => _sayac.value = yeniDeger;
//burada 2 tane fonksiyon belirledim. çeşitli fonksiyonlar yazılabilir.
void arttir() {
sayac = sayac + 1;
}
void azalt() {
sayac = sayac - 1;
}
}
I am using this code for main page.
import 'package:flutter/material.dart';
import 'package:flutter_ilk_proje/sayac_controllerEx.dart';
import 'package:get/get.dart';
import 'package:http/http.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
//Burada controller değşkenlerini vs getiriyorum.
SayacController _controller = Get.put(SayacController());
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: Scaffold(
appBar: AppBar(
title: Text('Material App Bar'),
),
body: Center(
child: InkWell(
onTap: () {
_controller.sayac("25");
},
child: Container(
child: Obx(
() => Text(_controller.sayac.toString()),
)),
),
),
),
);
}
}
and I'am getting this error
Exception has occurred.
NoSuchMethodError (NoSuchMethodError: Class 'int' has no instance method 'call'.
Receiver: 5
Tried calling: call("25"))
Screenshots about codes.
https://ibb.co/LP85JGR
https://ibb.co/YpFHjQF
https://ibb.co/HqPhxHd
It is really hard to guess what you may have meant.
Should this line: _controller.sayac("25"); maybe be _controller.sayac = 25;?
Anyway, _controller.sayac("25"); is plain wrong. sayac is a property. You can read it, you can write it, you cannot call it like that.
That said, you seem to try to get by with the bare minimum. Don't do this. Dart is such a wonderful language and it will help you all along the way, if you use it. Get a good linter (did you turn yours off? There should be one by default now...) and let it explain why you need to be verbose and explicit in everything you do and the language will support you as much as possible. This error that you got would be a compile time error if you had used the power of Dart.
I'm trying to find the coordinates for the screen while I'm outside of the app. I found a way to get the coordinates inside the app by this way.
import 'dart:io';
import 'package:flutter/material.dart';
import 'dart:async';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
home: new MyHomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
GlobalKey key = GlobalKey();
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Material(
child: Listener(
child: SizedBox.expand(
key: key,
child: GestureDetector(
onPanUpdate: (details) {
print(details.globalPosition);
},
),
),
),
),
);
}
}
I/flutter ( 9587): Offset(149.4, 182.0)
I/flutter ( 9587): Offset(148.6, 182.8)
I/flutter ( 9587): Offset(148.6, 183.4)
This obviously works inside the app. Is there a way to know the same positions outside of the app. That means like Even shows the location when dragged in the home screen or any other app
Is the way to do it by creating a background service? if so How do you get the app screen(1st picture) and phone screen meaning working any where on the phone(2nd image) to work together?
Edit: Is there a way to get the pointer location data from settings > Developer options > Input > Pointer location
Any help would be appreciated!
Maybe you can try pyautogui. position but this work only for your desktop screen, but if you have an Android studio you can try it and after this, you can calculate the position of your android screen you need not the screen resolution of your desktop, and if you put an Android emulation to corner you can easily calculate with this math operation 1:x(times2. Or if you have only mobile devices you can try some apps in PlayStore
import time
import pyautugui as pg
time.sleep(5)
print(pg.position())
Firstly, I was trying to import a project that contains a complete Webview and I was surprised that even after running flutter clean ; flutter pub get I would still get errors.
I then tried to recreate the demo app following https://flutter.dev/docs/get-started/codelab which was working fine at first yesterday. From here I saw that I get the same errors,
Here's my .dart code for the demo app :
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
Sorry for showing the errors by a screenshot but the logs when building are way too long to share, since I think it's a common problem it shouldn't be that troublesome, let me know if you need the errors so I'll do a pastebin.
Thank you guys
It looks like you maybe getting some errors while getting the dependencies and flutter is not being downloaded correctly.
If its still happening review your dependencies and do a:
flutter clean
flutter pub upgrade
If it still happens, review the log of flutter pub get to see what error you maybe getting from the dependencies.
There is another command that could work if your case is that the dependencies are not being updated locally, not on your project, but on your flutter cache. You can use:
flutter pub cache repair
The only solution I found was to delete the Flutter SDK (just delete the folder you downloaded) and to reinstall via git just because I prefer it that way.
I also moved the SDK from C:/Users/my_user/ to C:/src.
I need to integrate Jitsi Meet in webview for our flutter application. Initially I used the following jitsi-meet plugin "https://pub.dev/packages/jitsi_meet" but unfortunately had to switch to InAppwebview plugin "https://pub.dev/packages/flutter_inappwebview" because of missing features such as jitsi reconnection after internet drop and participant information in jitsi-meet plugin. I have successfully integrated the jitsi in webview but have no idea how to include jitsi callbacks like onConferenceJoined, onParticipantLeft etc. Any help would be much appreciated
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:permission_handler/permission_handler.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await Permission.camera.request();
await Permission.microphone.request();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return MaterialApp(home: InAppWebViewPage());
}
}
class InAppWebViewPage extends StatefulWidget {
#override
_InAppWebViewPageState createState() => new _InAppWebViewPageState();
}
class _InAppWebViewPageState extends State<InAppWebViewPage> {
InAppWebViewController _webViewController;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("InAppWebView")),
body: Container(
child: Column(children: <Widget>[
Expanded(
child: Container(
child: InAppWebView(
initialUrl: "https://meet.jit.si/hello",
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
mediaPlaybackRequiresUserGesture: false,
debuggingEnabled: true,
),
),
onWebViewCreated: (InAppWebViewController controller) {
_webViewController = controller;
},
androidOnPermissionRequest:
(InAppWebViewController controller, String origin,
List<String> resources) async {
return PermissionRequestResponse(
resources: resources,
action: PermissionRequestResponseAction.GRANT);
}),
),
),
])));
}
}
Sorry to say, but you can't access such features through webview, because when you access thorough webview it's similar to open the site on the browser as a user. You can use Jitsi SDK or plugins which allow you to modify the settings.
Suggestion: Use the jitsi meet plugin which you had used before it already has such features as which you want:
onConferenceWillJoin Meeting is loading.
onConferenceJoined User has joined meeting.
onConferenceTerminated User has exited the conference.
onPictureInPictureWillEnter User entered PIP mode.
onPictureInPictureTerminated User exited PIP mode.
onError Error has occurred with listening to meeting events.
But there is no feature for participant information. But you can achieve this all by hosting your own jitsi server, which would allow you to either customize it or directly have such settings on your custom domain so that on the app you can simply access through webview.
I have used this plugin for a long time and made an app published on the play store. Check that out do you something similar to that? app name Just Meet. If you want like that then I can help you out with my repo.
Maybe you can use socket.io to communicate between the app and webview.
This question already has answers here:
How to take a screenshot of the current widget - Flutter
(4 answers)
Closed 2 years ago.
How can I implement the in-app screenshot functionality in flutter android?
I need this function to take a screenshot of the app screen and share the picture.
are there any plugins?
I have shared an example of code where I have used Screenshot plugin available on pub.dev along with permission handler and path provider plugin. Basically this plugin wraps your widgets inside RenderRepaintBoundary and creates an screenshot of your widget.
main.dart
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:screenshot/screenshot.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Screenshot Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
File _imageFile;
//Create an instance of ScreenshotController
ScreenshotController screenshotController = ScreenshotController();
#override
void initState() {
// TODO: implement initState
super.initState();
_requestPermission();
}
_requestPermission() async {
Map<Permission, PermissionStatus> statuses = await [
Permission.storage,
].request();
final info = statuses[Permission.storage].toString();
print(info);
}
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Container(
child: new Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Screenshot(
controller: screenshotController,
child: Column(
children: <Widget>[
Text(
'You have pushed the button this many times:' +
_counter.toString(),
),
FlutterLogo(),
],
),
),
_imageFile != null ? Image.file(_imageFile) : Container(),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () async {
_incrementCounter();
_imageFile = null;
screenshotController
.capture(delay: Duration(milliseconds: 10))
.then((File image) async {
//print("Capture Done");
setState(() {
_imageFile = image;
});
final result =
await ImageGallerySaver.saveImage(image.readAsBytesSync());
print("File Saved to Gallery $result");
}).catchError((onError) {
print("Error: $onError");
});
},
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
_saved(File image) async {
final result = await ImageGallerySaver.saveImage(image.readAsBytesSync());
print("File Saved to Gallery");
}
}
Packages used:
screenshot:
image_gallery_saver: ^1.1.0
permission_handler:
path_provider: ^1.6.24
You will need to specify storage permissions in AndroidManifest file as below:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
To take screenshots within flutter app of the current use this screenshot package it also has example and documentation for saving the image to a folder and as well as to gallery which can also be google photos using 2 other plugins which you can find there only. I have used this plugin and it works really well if you havep any queries then you can comment below. Hope this helps you out!