How to solve flutter inappwebview stopped working? - flutter

I have created an app to display html file with flutter_inappwebview plugin but i got errors as below:
pubspec.yaml
flutter_inappwebview: ^2.1.0
here is my main.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
InAppWebViewController webView;
String url = "";
double progress = 0;
#override
void initState() {
super.initState();
}
#override
void dispose() {
super.dispose();
}
#override
Widget build(BuildContext context) {
return Container(
height: 200,
child: InAppWebView(
initialUrl: 'https://www.google.com',
),
);
}
}
when I run the code the app unfortunately stop.
This is an error in Emulator.
This is an error in Android Studio 3.5.3
Any solutions thanks?

After looking at issue in github issue link, here is the solution:
From
dependencies:
flutter_inappwebview: ^2.1.0+1
To
dependencies:
flutter_inappwebview:
git:
url: https://github.com/pichillilorenzo/flutter_inappwebview.git
Then run flutter clean and then run the app. It should solve the problem.

Related

File object not opening a local file in a flutter project but works in a dart file not part of the flutter project

So I want to open an SVG file in my main.dart file and for that, I'm using the File class and the readAsStringSync() method. But it seems like the File object cannot open the file.
And when I try to do the same thing outside of the flutter project, it seems to be working fine.
Here is the folder structure that I'm using in both the flutter project and the dart project.
lib
|_ main.dart
|_ world.svg
Here is the main.dart of the flutter project:
import 'dart:io';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return const MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
#override
Widget build(BuildContext context) {
final xml = File('world.svg').readAsStringSync();
print(xml);
return Scaffold(
appBar: AppBar(title: Text('Testing')),
);
}
}
Error
And here is the main.dart of the dart project:
import 'dart:io';
void main() {
String file = File('world.svg').readAsStringSync();
print(file.length);
}
Output

Flutter, how to make 'webview_flutter' set to chrome

I want to make "webview_flutter" package run only on the chrome browser.
But I don't know if this is possible or not.
Or if I'm misunderstanding something, please let me know as well.
You can try the plugin flutter_inappwebview. To do that, you need to use the ChromeSafariBrowser class.
It uses Chrome Custom Tabs on Android and SFSafariViewController on iOS.
You can initialize the ChromeSafariBrowser instance with an InAppBrowser fallback instance.
an exemple :
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
class MyInAppBrowser extends InAppBrowser {
#override
Future onLoadStart(String url) async {
print("\n\nStarted $url\n\n");
}
#override
Future onLoadStop(String url) async {
print("\n\nStopped $url\n\n");
}
#override
void onLoadError(String url, int code, String message) {
print("\n\nCan't load $url.. Error: $message\n\n");
}
#override
void onExit() {
print("\n\nBrowser closed!\n\n");
}
}
class MyChromeSafariBrowser extends ChromeSafariBrowser {
MyChromeSafariBrowser(browserFallback) : super(bFallback:
browserFallback);
#override
void onOpened() {
print("ChromeSafari browser opened");
}
#override
void onLoaded() {
print("ChromeSafari browser loaded");
}
#override
void onClosed() {
print("ChromeSafari browser closed");
}
}
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
final ChromeSafariBrowser browser = new MyChromeSafariBrowser(new
MyInAppBrowser());
#override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('ChromeSafariBrowser Example'),
),
body: Center(
child: RaisedButton(
onPressed: () async {
await widget.browser.open(
url: "https://flutter.dev/",
options: ChromeSafariBrowserClassOptions(
androidChromeCustomTabsOptions:
AndroidChromeCustomTabsOptions(addShareButton:
false),
iosSafariOptions:
IosSafariOptions(barCollapsingEnabled: true)));
},
child: Text("Open Chrome Safari Browser")),
),
),
);
}
}
or you can make your own browser follow this exemple :
https://inappwebview.dev/docs/in-app-webview/basic-usage/

Code execution stopped at await in async function in flutter while implementing Text to Speech

I am trying the text to speech feature in a flutter, but it is not working.
I tried many code examples from the internet and googled but did not find why not working in my project.
To keep it simple I was trying in one simple file but still, it is not working.
On click of a button, the first print statement is executing but after that not get anything.
Below is the code
import 'package:flutter/material.dart';
import 'package:flutter_tts/flutter_tts.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late FlutterTts flutterTts;
#override
initState() {
super.initState();
initTts();
}
initTts() {
flutterTts = FlutterTts();
}
#override
void dispose() {
super.dispose();
flutterTts.stop();
}
Future _speak() async {
print("1");
await flutterTts.speak("Hello");
print("2");
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Flutter TTS'),
),
body: InkWell(
onTap: _speak,
child: Text("Click"),
)
),
);
}
}
The console output is
Performing hot reload...
Syncing files to device Android SDK built for x86...
Reloaded 1 of 568 libraries in 544ms.
I/flutter (21300): 1

flutte app run in background only if device is connected to usb charger

I try to validate simple task => persiste the vibration when device is horizontal (user sitdown)
Currently it's work when the screen is off only if device is connected to the laptop or usb charger. I try workmanager and android_alarm_manager but I have same issue. I'm doing something wrong ? or it's Impossible ?
Here is a simple reproduce code to test timer and vibration in background when device is connected and not connected.
import 'package:android_alarm_manager/android_alarm_manager.dart';
import 'package:flutter/material.dart';
import 'package:vibration/vibration.dart';
import 'dart:async';
main() async {
WidgetsFlutterBinding.ensureInitialized();
await AndroidAlarmManager.initialize();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Timer _timer;
test_vibration() {
_timer= Timer.periodic(const Duration(seconds: 1), (timer) {
Vibration.vibrate();
});
}
#override
void initState() {
// TODO: implement initState
super.initState();
AndroidAlarmManager.periodic(Duration(seconds: 1), 0, test_vibration());
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center()
),
);
}
}
here is more complet example with accelerometer
import 'package:sensors/sensors.dart';
import 'package:android_alarm_manager/android_alarm_manager.dart';
import 'package:flutter/material.dart';
import 'package:vibration/vibration.dart';
import 'dart:async';
main() async {
WidgetsFlutterBinding.ensureInitialized();
await AndroidAlarmManager.initialize();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List<double> _accelerometerValues;
List<StreamSubscription<dynamic>> _streamSubscriptions =
<StreamSubscription<dynamic>>[];
test_vibration() {
_streamSubscriptions.add(accelerometerEvents.listen((AccelerometerEvent event) { // Stream accelerometre
_accelerometerValues = <double>[event.y]; read accelerometer y
if (event.y>6.0||event.y<-6.0){ //device vertical
}else{ // device horizontal
Vibration.vibrate();
}
}));
}
#override
void initState() {
// TODO: implement initState
super.initState();
_streamSubscriptions.add(accelerometerEvents.listen((AccelerometerEvent event) {
setState(() {
_accelerometerValues = <double>[event.y];
});
AndroidAlarmManager.periodic(Duration(seconds: 1), 0, test_vibration());
}));
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center()
),
);
}
}
solution I found :
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

Flutter ':path_provider:compileDebugJavaWithJavac' Error

Im having problem in the path provider dependencies in flutter.
I've been trying to find a solution for this for almost 2 day now..
please help me..
My dependencies
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.0
hive: ^1.4.1+1
hive_flutter: ^0.3.0+2
path_provider: ^1.6.5
http: ^0.12.2
My Code (even without code its running the error as long as a add the path provider)
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:convert';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:hive/hive.dart';
import 'package:http/http.dart' as http;
void main() async {
//Hive.initFlutter();
WidgetsFlutterBinding.ensureInitialized();
//final appDocDir = await getApplicationDocumentsDirectory();
// Hive.init(appDocDir.path);
var box = await Hive.openBox('employee');
runApp(
MaterialApp(home: Home()),
);
}
class Home extends StatefulWidget {
Home({Key key}) : super(key: key);
#override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Sample'),
),
body: Center(),
);
}
}
I've resolved this using by doing flutter pub downgrade in the terminal