pichillilorenzo / flutter_inappwebview

A Flutter plugin that allows you to add an inline webview, to use a headless webview, and to open an in-app browser window.
https://inappwebview.dev
Apache License 2.0
3.22k stars 1.57k forks source link

ChromeSafariBrowser example not working #52

Open behinime opened 5 years ago

behinime commented 5 years ago

Running the code given as example:

import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.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");
  }

}

MyInAppBrowser inAppBrowserFallback = new MyInAppBrowser();

class MyChromeSafariBrowser extends ChromeSafariBrowser {

  MyChromeSafariBrowser(browserFallback) : super(browserFallback);

  @override
  void onOpened() {
    print("ChromeSafari browser opened");
  }

  @override
  void onLoaded() {
    print("ChromeSafari browser loaded");
  }

  @override
  void onClosed() {
    print("ChromeSafari browser closed");
  }
}

MyChromeSafariBrowser chromeSafariBrowser = new MyChromeSafariBrowser(inAppBrowserFallback);

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('Flutter InAppBrowser Plugin example app'),
        ),
        body: new Center(
          child: new RaisedButton(onPressed: () {
            chromeSafariBrowser.open("https://flutter.io/", options: {
                  "addShareButton": false,
                  "toolbarBackgroundColor": "#000000",
                  "dismissButtonStyle": 1,
                  "preferredBarTintColor": "#000000",
                },
              optionsFallback: {
                "toolbarTopBackgroundColor": "#000000",
                "closeButtonCaption": "Close"
              });
          },
          child: Text("Open ChromeSafariBrowser")
          ),
        ),
      ),
    );
  }
}

I can run the application, but when i try to click the button that have to open ChromeSafariBrowser, it fails.

Console is returning this:

V/Surface ( 6944): sf_framedrop debug : 0x4f4c, game : false, logging : 0 D/ViewRootImpl@b4ebb2bMainActivity: Relayout returned: old=[0,0][1080,1920] new=[0,0][1080,1920] result=0x7 surface={valid=true 541222268928} changed=true D/mali_winsys( 6944): EGLint new_window_surface(egl_winsys_display , void , EGLSurface, EGLConfig, egl_winsys_surface *, egl_color_buffer_format , EGLBoolean) returns 0x3000, [1080x1920]-format:1 D/OpenGLRenderer( 6944): eglCreateWindowSurface = 0x7e03426cd0 D/SurfaceView( 6944): BG show() Surface(name=Background for - SurfaceView - com.impiantigarantiti.impiantigarantiti/com.impiantigarantiti.impiantigarantiti.MainActivity@af4b921@2) io.flutter.view.FlutterView{af4b921 VFE...... .F...... 0,0-1080,1920} V/Surface ( 6944): sf_framedrop debug : 0x4f4c, game : false, logging : 0 D/SurfaceView( 6944): surfaceCreated 1 io.flutter.view.FlutterView{af4b921 VFE...... .F...... 0,0-1080,1920} D/mali_winsys( 6944): EGLint new_window_surface(egl_winsys_display , void , EGLSurface, EGLConfig, egl_winsys_surface *, egl_color_buffer_format , EGLBoolean) returns 0x3000, [1080x1920]-format:1 D/SurfaceView( 6944): surfaceChanged (1080,1920) 1 io.flutter.view.FlutterView{af4b921 VFE...... .F...... 0,0-1080,1920} E/BpSurfaceComposerClient( 6944): Failed to transact (-1) D/SurfaceView( 6944): BG destroy() Surface(name=Background for - SurfaceView - com.impiantigarantiti.impiantigarantiti/com.impiantigarantiti.impiantigarantiti.MainActivity@af4b921@1) io.flutter.view.FlutterView{af4b921 VFE...... .F...... 0,0-1080,1920} E/BpSurfaceComposerClient( 6944): Failed to transact (-1) D/ViewRootImpl@b4ebb2bMainActivity: Relayout returned: old=[0,0][1080,1920] new=[0,0][1080,1920] result=0x3 surface={valid=true 541222268928} changed=false D/ViewRootImpl@b4ebb2bMainActivity: MSG_WINDOW_FOCUS_CHANGED 1 V/InputMethodManager( 6944): Starting input: tba=android.view.inputmethod.EditorInfo@f7c2664 nm : com.impiantigarantiti.impiantigarantiti ic=null I/InputMethodManager( 6944): startInputInner - mService.startInputOrWindowGainedFocus D/ViewRootImpl@b4ebb2bMainActivity: ViewPostIme pointer 0 D/ViewRootImpl@b4ebb2bMainActivity: ViewPostIme pointer 1 E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): Failed to handle method call E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): at com.pichillilorenzo.flutter_inappbrowser.InAppBrowserFlutterPlugin.onMethodCall(InAppBrowserFlutterPlugin.java:100) E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201) E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): at io.flutter.view.FlutterNativeView$PlatformMessageHandlerImpl.handleMessageFromDart(FlutterNativeView.java:188) E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:202) E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): at android.os.MessageQueue.next(MessageQueue.java:325) E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): at android.os.Looper.loop(Looper.java:142) E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): at android.app.ActivityThread.main(ActivityThread.java:6944) E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) E/MethodChannel#com.pichillilorenzo/flutter_inappbrowser( 6944): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) E/flutter ( 6944): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference, null) E/flutter ( 6944): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7) E/flutter ( 6944): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302:33) E/flutter ( 6944): E/flutter ( 6944): #2 ChromeSafariBrowser.open (package:flutter_inappbrowser/flutter_inappbrowser.dart:491:35) E/flutter ( 6944): E/flutter ( 6944): #3 _MyAppState.build. (package:impiantigarantiti/main.dart:77:33) E/flutter ( 6944): #4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:513:14) E/flutter ( 6944): #5 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:568:30) E/flutter ( 6944): #6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:120:24) E/flutter ( 6944): #7 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9) E/flutter ( 6944): #8 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7) E/flutter ( 6944): #9 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:369:9) E/flutter ( 6944): #10 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12) E/flutter ( 6944): #11 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11) E/flutter ( 6944): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:214:19) E/flutter ( 6944): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:192:22) E/flutter ( 6944): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:149:7) E/flutter ( 6944): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7) E/flutter ( 6944): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7) E/flutter ( 6944): #17 _rootRunUnary (dart:async/zone.dart:1136:13) E/flutter ( 6944): #18 _CustomZone.runUnary (dart:async/zone.dart:1029:19) E/flutter ( 6944): #19 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7) E/flutter ( 6944): #20 _invoke1 (dart:ui/hooks.dart:223:10) E/flutter ( 6944): #21 _dispatchPointerDataPacket (dart:ui/hooks.dart:144:5) E/flutter ( 6944):

pichillilorenzo commented 5 years ago

Let me know if the new version 0.6.0 works.