droibit / flutter_custom_tabs

A Flutter plugin for mobile apps to launch a URL in Custom Tabs/SFSafariViewController.
https://pub.dartlang.org/packages/flutter_custom_tabs
Apache License 2.0
137 stars 68 forks source link

Not show directly #28

Closed Aoi-hosizora closed 4 years ago

Aoi-hosizora commented 4 years ago

I use flutter_custom_tabs 0.6.0 on android emulate and my mobile phone.

In emulate (Android 8) it works well (although the system is not support browser exactly). But in my own mobile phone (Android 10), a single launch() action has no effect. If I invoke launch() twice, the last action has no effect also, but after I press the back button, the first page will be shown (navigator changed only when pressed back button).

There is my code: (nearly is same with demo)

Future launchInBrowser({BuildContext context, String url}) async {
  try {
    await launch(
      url,
      option: CustomTabsOption(
        toolbarColor: Theme.of(context).primaryColor,
        enableDefaultShare: true,
        enableUrlBarHiding: false,
        showPageTitle: true,
        animation: CustomTabsAnimation(
          startEnter: 'slide_up',
          startExit: 'android:anim/fade_out',
          endEnter: 'android:anim/fade_in',
          endExit: 'slide_down',
        ),
        extraCustomTabs: [
          'org.mozilla.firefox',
          'com.microsoft.emmx',
        ],
      ),
    );
  } catch (ex) {
    return Future.error(ex);
  }
}
ListTile(
  onTap: () => launchInBrowser(context: context, url: xxx),
  xxx
)
Fleximex commented 4 years ago

You are using a custom CustomTabsAnimation with none existing animations. Both 'slide_down' and 'slide_up' miss the 'android:anim/' prefix. You probably took the format from the default CustomTabsAnimation.slideIn() which actually has them wrongly defined. This is a fault in the flutter_custom_tabs package.

https://github.com/droibit/flutter_custom_tabs/issues/21

You can fix it simply by replacing

animation: CustomTabsAnimation(
        startEnter: 'slide_up',
        startExit: 'android:anim/fade_out',
        endEnter: 'android:anim/fade_in',
        endExit: 'slide_down',
    ),

with

animation: const CustomTabsAnimation(
        startEnter: 'android:anim/slide_up',
        startExit: 'android:anim/slide_out_left',
        endEnter: 'android:anim/slide_in_left',
        endExit: 'android:anim/slide_down',
    ),

You can use const (a constant) because you already know the animation names. If this doesn't work then the slide_up and slide_down don't exist and you should add them yourself as an .xml: https://stackoverflow.com/questions/23925907/slidedown-and-slideup-layout-with-animation

zanecidan commented 4 years ago

I'm also facing this problem, only in release mode after I updated my flutter version to latest Stable version. Previously I was using 1.9.1 and it works well. Now debug mode works normally as well.

Aoi-hosizora commented 4 years ago

Thx. I will try it later. Now I'm using flutter_web_browser. (Sorry for late reply)

joaoarmando commented 4 years ago

@zanecidan I'm facing with it today, same here! After upgrade to the last stable version of Flutter, I have this problem. I already tried to change the CustomTabsAnimation() but nothing working here. Did you find a solution?

zanecidan commented 4 years ago

@joaoarmando In the end I open the plugin files and fixed the animation parameters as per @Fleximex suggested.