flutter_boost icon indicating copy to clipboard operation
flutter_boost copied to clipboard

Android同时接入两个fragment,用add/hide/show方式显示,出现第一个页面点击操作响应了第二个页面的事件问题,Demo同样出现此问题!!同样显示方式换成v4.fragment原生页面就不会有问题。

Open MuJie opened this issue 6 years ago • 5 comments

现象:Android一个页面同时接入两个fragment,用add/hide/show方式显示fragment;第一次点击fragment1显示-正常(内容+点击);第二次切换打开fragment2显示-正常(内容+点击);重点来了,切回fragment1,内容显示正常,点击响应了fragment2相同位置的点击事件。但fragment替换成v4.fragment就不会出现此问题。

复现简易Demo

Android Native侧修改

官方Demo 打开的flutter fragment page里,有4个tab的fragment,前两个tab改成add/hide/show方式显示不同页面。官方直接用replace方式,页面内容也一样,导致部分问题可能暴露不出来。

FlutterFragmentPageActivity类里修改如下:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        if(mTab1 == v) {
            mTab1.setBackgroundColor(Color.YELLOW);
            hideAll(transaction);
            if (mFragment1 == null) {
                mFragment1 = new FlutterFragment.NewEngineFragmentBuilder().url("flutterFragment1").build();
                transaction.add(R.id.fragment_stub, mFragment1);
            } else {
                transaction.show(mFragment1);
            }

        }else if(mTab2 == v) {
            hideAll(transaction);
            mTab2.setBackgroundColor(Color.YELLOW);
            if (mFragment2 == null) {
                mFragment2 = new FlutterFragment.NewEngineFragmentBuilder().url("flutterFragment2").build();
                transaction.add(R.id.fragment_stub, mFragment2);
            } else {
                transaction.show(mFragment2);
            }
        }

private void hideAll(FragmentTransaction transaction) {
        if (mFragment1 != null) {
            transaction.hide(mFragment1);
        }
        if (mFragment2 != null) {
            transaction.hide(mFragment2);
        }
        if (mFragment3 != null) {
            transaction.hide(mFragment3);
        }
        if (mFragment4 != null) {
            transaction.hide(mFragment4);
        }
    }

Dart修改

保证两个Fragment内嵌两个不同页面,有相同位置的按钮,点击效果不一样。做区别

simple_page_widgets.dart里的FragmentRouteWidget

class FragmentRouteWidget extends StatelessWidget {
  final Map params;

  FragmentRouteWidget(this.params);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('flutter_boost_example'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.only(top: 80.0),
            child: Text(
              "This is a flutter fragment1",
              style: TextStyle(fontSize: 28.0, color: Colors.blue),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Container(
            margin: const EdgeInsets.only(top: 32.0),
            child: Text(
              params['tag'] ?? '',
              style: TextStyle(fontSize: 28.0, color: Colors.red),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Expanded(child: Container()),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open native page 111',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
//            onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
            onTap: () => Toast.show(
                '第111个fragment点击111',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
//            onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
            onTap: () => Toast.show(
                '第111个fragment点击222',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter fragment page 111',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
            onTap: () =>
//                FlutterBoost.singleton.open("sample://flutterFragmentPage"),
            Toast.show(
                '第111个fragment点击333',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          )
        ],
      ),
    );
  }
}

FragmentRouteWidget2为复制FragmentRouteWidget的代码,仅响应的点击事件效果不同。

class FragmentRouteWidget2 extends StatelessWidget {
  final Map params;

  FragmentRouteWidget2(this.params);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('flutter_boost_example2'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.only(top: 80.0),
            child: Text(
              "This is a flutter fragment222",
              style: TextStyle(fontSize: 28.0, color: Colors.blue),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Container(
            margin: const EdgeInsets.only(top: 32.0),
            child: Text(
              params['tag'] ?? '',
              style: TextStyle(fontSize: 28.0, color: Colors.red),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Expanded(child: Container()),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open native page 222',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
//            onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
            onTap: () => Toast.show(
                '第2个fragment点击',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
            onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter fragment page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
            onTap: () =>
                FlutterBoost.singleton.open("sample://flutterFragmentPage"),
          )
        ],
      ),
    );
  }
}

Flutter Boost Version 0.1.66 Target Platform: Android Target OS version/browser: Android8.0.0 Devices: 小米MIX2

➜  ~ flutter doctor -v       
[✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.12.5 16F73, locale
    zh-Hans-CN)
    • Flutter version 1.9.1+hotfix.6 at /Users/user/flutter
    • Framework revision 68587a0916 (5 months ago), 2019-09-13 19:46:58 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0

 
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/user/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at:
      /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/bin/java
    • Java version Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses

[✗] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS
      development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin
        code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install:
        sudo gem install cocoapods

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/setup/#android-setup for detailed
      instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2019.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 40.2.3
    • Dart plugin version 192.7402

[✓] Connected device (1 available)
    • MIX 2 • 840612b9 • android-arm64 • Android 8.0.0 (API 26)

! Doctor found issues in 3 categories.

MuJie avatar Feb 13 '20 06:02 MuJie

现象:Android一个页面同时接入两个fragment,用add/hide/show方式显示fragment;第一次点击fragment1显示-正常(内容+点击);第二次切换打开fragment2显示-正常(内容+点击);重点来了,切回fragment1,内容显示正常,点击响应了fragment2相同位置的点击事件。但fragment替换成v4.fragment就不会出现此问题。

复现简易Demo

Android Native侧修改

官方Demo 打开的flutter fragment page里,有4个tab的fragment,前两个tab改成add/hide/show方式显示不同页面。官方直接用replace方式,页面内容也一样,导致部分问题可能暴露不出来。

FlutterFragmentPageActivity类里修改如下:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        if(mTab1 == v) {
            mTab1.setBackgroundColor(Color.YELLOW);
            hideAll(transaction);
            if (mFragment1 == null) {
                mFragment1 = new FlutterFragment.NewEngineFragmentBuilder().url("flutterFragment1").build();
                transaction.add(R.id.fragment_stub, mFragment1);
            } else {
                transaction.show(mFragment1);
            }

        }else if(mTab2 == v) {
            hideAll(transaction);
            mTab2.setBackgroundColor(Color.YELLOW);
            if (mFragment2 == null) {
                mFragment2 = new FlutterFragment.NewEngineFragmentBuilder().url("flutterFragment2").build();
                transaction.add(R.id.fragment_stub, mFragment2);
            } else {
                transaction.show(mFragment2);
            }
        }

private void hideAll(FragmentTransaction transaction) {
        if (mFragment1 != null) {
            transaction.hide(mFragment1);
        }
        if (mFragment2 != null) {
            transaction.hide(mFragment2);
        }
        if (mFragment3 != null) {
            transaction.hide(mFragment3);
        }
        if (mFragment4 != null) {
            transaction.hide(mFragment4);
        }
    }

Dart修改

保证两个Fragment内嵌两个不同页面,有相同位置的按钮,点击效果不一样。做区别

simple_page_widgets.dart里的FragmentRouteWidget

class FragmentRouteWidget extends StatelessWidget {
  final Map params;

  FragmentRouteWidget(this.params);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('flutter_boost_example'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.only(top: 80.0),
            child: Text(
              "This is a flutter fragment1",
              style: TextStyle(fontSize: 28.0, color: Colors.blue),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Container(
            margin: const EdgeInsets.only(top: 32.0),
            child: Text(
              params['tag'] ?? '',
              style: TextStyle(fontSize: 28.0, color: Colors.red),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Expanded(child: Container()),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open native page 111',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
//            onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
            onTap: () => Toast.show(
                '第111个fragment点击111',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
//            onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
            onTap: () => Toast.show(
                '第111个fragment点击222',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter fragment page 111',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
            onTap: () =>
//                FlutterBoost.singleton.open("sample://flutterFragmentPage"),
            Toast.show(
                '第111个fragment点击333',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          )
        ],
      ),
    );
  }
}

FragmentRouteWidget2为复制FragmentRouteWidget的代码,仅响应的点击事件效果不同。

class FragmentRouteWidget2 extends StatelessWidget {
  final Map params;

  FragmentRouteWidget2(this.params);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('flutter_boost_example2'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.only(top: 80.0),
            child: Text(
              "This is a flutter fragment222",
              style: TextStyle(fontSize: 28.0, color: Colors.blue),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Container(
            margin: const EdgeInsets.only(top: 32.0),
            child: Text(
              params['tag'] ?? '',
              style: TextStyle(fontSize: 28.0, color: Colors.red),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Expanded(child: Container()),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open native page 222',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
//            onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
            onTap: () => Toast.show(
                '第2个fragment点击',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
            onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter fragment page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
            onTap: () =>
                FlutterBoost.singleton.open("sample://flutterFragmentPage"),
          )
        ],
      ),
    );
  }
}

Flutter Boost Version 0.1.66 Target Platform: Android Target OS version/browser: Android8.0.0 Devices: 小米MIX2

➜  ~ flutter doctor -v       
[✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.12.5 16F73, locale
    zh-Hans-CN)
    • Flutter version 1.9.1+hotfix.6 at /Users/user/flutter
    • Framework revision 68587a0916 (5 months ago), 2019-09-13 19:46:58 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0

 
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/user/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at:
      /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/bin/java
    • Java version Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses

[✗] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS
      development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin
        code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install:
        sudo gem install cocoapods

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/setup/#android-setup for detailed
      instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2019.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 40.2.3
    • Dart plugin version 192.7402

[✓] Connected device (1 available)
    • MIX 2 • 840612b9 • android-arm64 • Android 8.0.0 (API 26)

! Doctor found issues in 3 categories.

现象:Android一个页面同时接入两个fragment,用add/hide/show方式显示fragment;第一次点击fragment1显示-正常(内容+点击);第二次切换打开fragment2显示-正常(内容+点击);重点来了,切回fragment1,内容显示正常,点击响应了fragment2相同位置的点击事件。但fragment替换成v4.fragment就不会出现此问题。

复现简易Demo

Android Native侧修改

官方Demo 打开的flutter fragment page里,有4个tab的fragment,前两个tab改成add/hide/show方式显示不同页面。官方直接用replace方式,页面内容也一样,导致部分问题可能暴露不出来。

FlutterFragmentPageActivity类里修改如下:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        if(mTab1 == v) {
            mTab1.setBackgroundColor(Color.YELLOW);
            hideAll(transaction);
            if (mFragment1 == null) {
                mFragment1 = new FlutterFragment.NewEngineFragmentBuilder().url("flutterFragment1").build();
                transaction.add(R.id.fragment_stub, mFragment1);
            } else {
                transaction.show(mFragment1);
            }

        }else if(mTab2 == v) {
            hideAll(transaction);
            mTab2.setBackgroundColor(Color.YELLOW);
            if (mFragment2 == null) {
                mFragment2 = new FlutterFragment.NewEngineFragmentBuilder().url("flutterFragment2").build();
                transaction.add(R.id.fragment_stub, mFragment2);
            } else {
                transaction.show(mFragment2);
            }
        }

private void hideAll(FragmentTransaction transaction) {
        if (mFragment1 != null) {
            transaction.hide(mFragment1);
        }
        if (mFragment2 != null) {
            transaction.hide(mFragment2);
        }
        if (mFragment3 != null) {
            transaction.hide(mFragment3);
        }
        if (mFragment4 != null) {
            transaction.hide(mFragment4);
        }
    }

Dart修改

保证两个Fragment内嵌两个不同页面,有相同位置的按钮,点击效果不一样。做区别

simple_page_widgets.dart里的FragmentRouteWidget

class FragmentRouteWidget extends StatelessWidget {
  final Map params;

  FragmentRouteWidget(this.params);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('flutter_boost_example'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.only(top: 80.0),
            child: Text(
              "This is a flutter fragment1",
              style: TextStyle(fontSize: 28.0, color: Colors.blue),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Container(
            margin: const EdgeInsets.only(top: 32.0),
            child: Text(
              params['tag'] ?? '',
              style: TextStyle(fontSize: 28.0, color: Colors.red),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Expanded(child: Container()),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open native page 111',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
//            onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
            onTap: () => Toast.show(
                '第111个fragment点击111',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
//            onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
            onTap: () => Toast.show(
                '第111个fragment点击222',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter fragment page 111',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
            onTap: () =>
//                FlutterBoost.singleton.open("sample://flutterFragmentPage"),
            Toast.show(
                '第111个fragment点击333',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          )
        ],
      ),
    );
  }
}

FragmentRouteWidget2为复制FragmentRouteWidget的代码,仅响应的点击事件效果不同。

class FragmentRouteWidget2 extends StatelessWidget {
  final Map params;

  FragmentRouteWidget2(this.params);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('flutter_boost_example2'),
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: const EdgeInsets.only(top: 80.0),
            child: Text(
              "This is a flutter fragment222",
              style: TextStyle(fontSize: 28.0, color: Colors.blue),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Container(
            margin: const EdgeInsets.only(top: 32.0),
            child: Text(
              params['tag'] ?? '',
              style: TextStyle(fontSize: 28.0, color: Colors.red),
            ),
            alignment: AlignmentDirectional.center,
          ),
          Expanded(child: Container()),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open native page 222',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
//            onTap: () => FlutterBoost.singleton.open("sample://nativePage"),
            onTap: () => Toast.show(
                '第2个fragment点击',
                context,
                duration: Toast.LENGTH_SHORT,
                gravity: Toast.BOTTOM),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.all(8.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
            onTap: () => FlutterBoost.singleton.open("sample://flutterPage"),
          ),
          InkWell(
            child: Container(
                padding: const EdgeInsets.all(8.0),
                margin: const EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 80.0),
                color: Colors.yellow,
                child: Text(
                  'open flutter fragment page',
                  style: TextStyle(fontSize: 22.0, color: Colors.black),
                )),
            onTap: () =>
                FlutterBoost.singleton.open("sample://flutterFragmentPage"),
          )
        ],
      ),
    );
  }
}

Flutter Boost Version 0.1.66 Target Platform: Android Target OS version/browser: Android8.0.0 Devices: 小米MIX2

➜  ~ flutter doctor -v       
[✓] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.12.5 16F73, locale
    zh-Hans-CN)
    • Flutter version 1.9.1+hotfix.6 at /Users/user/flutter
    • Framework revision 68587a0916 (5 months ago), 2019-09-13 19:46:58 -0700
    • Engine revision b863200c37
    • Dart version 2.5.0

 
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
    • Android SDK at /Users/user/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-29, build-tools 29.0.2
    • Java binary at:
      /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/bin/java
    • Java version Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses

[✗] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS
      development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin
        code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install:
        sudo gem install cocoapods

[!] Android Studio (not installed)
    • Android Studio not found; download from
      https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/setup/#android-setup for detailed
      instructions).

[✓] IntelliJ IDEA Ultimate Edition (version 2019.2.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 40.2.3
    • Dart plugin version 192.7402

[✓] Connected device (1 available)
    • MIX 2 • 840612b9 • android-arm64 • Android 8.0.0 (API 26)

! Doctor found issues in 3 categories.

感觉是两个Fragment导致的混乱,你试试对第一个Fragment操作完,delay完再显示第二个fragment 可以吗

ruidge avatar Feb 26 '20 09:02 ruidge

@ruidge 已经试过,无效。 同一个transaction事务,每次hide all 之后delay3秒显示另一个fragment;或者每次操作重新开启一个transaction事务;依然会出现这个问题,从第二个fragment切换回第一个fragment,内容显示正确,点击事件响应了第二个fragment的事件。 有兴趣的话,可以拿官方的Demo按我方案接入一下,试试。。私聊了官方技术人员也承认用add/hide/show有此问题,但仅提供replace方式,无解决方案。想想回滚成本和replace可能造成的重启影响做对比,暂时接受replace方案(内心其实是拒绝的)。

MuJie avatar Feb 27 '20 03:02 MuJie

出现第一个页面点击操作响应了第二个页面的事件问题,我遇到过这种问题,不过是因为第二个页面没有显示出来,但是事件却响应了。原因是Fragment开启了硬件加速导致第二个页面透明

tomxutao avatar Mar 14 '20 15:03 tomxutao

@tomxutao Hello,您说的那种情况我们之前在接flutter时也遇到过并解决了。但现在接的是flutter_boost,之前那套方案已经不用了。。而且这次现象跟你说的情况还是不同的,这次是页面正常显示,但事件会响应另一个页面的。。Native同样代码用Android官方提供的v4.fragment是不会出现此问题的。。所以我觉得问题可能还是跟flutter_boost提供的fragment有关。

MuJie avatar Mar 17 '20 03:03 MuJie

@MuJie 看了下, 应该是通过show/hide 显示Fragment时, 没有通过onHiddenChanged方法触发boost生命周期。 这问题已定位,PR: https://github.com/alibaba/flutter_boost/pull/637

Firewayer avatar Mar 24 '20 03:03 Firewayer