BilalShahid13 / PersistentBottomNavBar

A highly customizable persistent bottom navigation bar for Flutter
BSD 3-Clause "New" or "Revised" License
528 stars 396 forks source link

Scrolling doesn't work when tapping on StatusBar in iOS #293

Closed fushihara closed 6 months ago

fushihara commented 2 years ago

https://user-images.githubusercontent.com/1039534/172230767-237ca38c-015d-4c01-9c0f-df5977a3093b.mov

I know that PrimaryScrollController is important. The ability to move the ScrollView to the top of the screen when the status bar in iOS is touched does not work via PersistentBottomNavBar.

In the first half of the video, ScreenA moves ScrollView to the top when the status bar is clicked without any problem. In the second half of the video, then, the ScrollView of ScreenB_Sub is not responding in ScreenB_Base when the status bar is clicked.

Please tell me how to fix it with just the _ScreenB_Base or _ScreenB_BaseState class for the convenience of existing code.

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:persistent_bottom_nav_bar/persistent-tab-view.dart';

Future<void> main() async {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: ScreenA(),
    );
  }
}

Widget getTextScrollWidget() {
  String text = List.generate(300, (index) {
    String bar = "x" * (index % 20);
    return "$bar No.${index + 100} $bar";
  }).join("\n");
  return SingleChildScrollView(
    child: Container(
        width: double.infinity,
        child: Text(
          text,
          textAlign: TextAlign.center,
        )),
  );
}

class ScreenA extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("TapStatusBarWorking"),
      ),
      body: Column(
        children: [
          Expanded(child: getTextScrollWidget()),
          Container(
            width: double.infinity,
            child: ElevatedButton(
              child: Text("PushNextScreen"),
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (BuildContext context) => ScreenB_Base(),
                  ),
                );
              },
            ),
          )
        ],
      ),
    );
  }
}

class ScreenB_Base extends StatefulWidget {
  @override
  State<ScreenB_Base> createState() => _ScreenB_BaseState();
}

class _ScreenB_BaseState extends State<ScreenB_Base> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("StatusBarTapNotWorking"),
        ),
        body: PersistentTabView(
          context,
          screens: [
            ScreenB_Sub(),
            ScreenB_Sub(),
          ],
          items: [
            PersistentBottomNavBarItem(
              icon: Icon(CupertinoIcons.home),
              title: "b-1",
              activeColorPrimary: CupertinoColors.activeBlue,
              inactiveColorPrimary: CupertinoColors.systemGrey,
            ),
            PersistentBottomNavBarItem(
              icon: Icon(CupertinoIcons.settings),
              title: "do not touch",
              activeColorPrimary: CupertinoColors.activeBlue,
              inactiveColorPrimary: CupertinoColors.systemGrey,
            ),
          ],
        ));
  }
}

class ScreenB_Sub extends StatefulWidget {
  @override
  State<ScreenB_Sub> createState() => _ScreenB_SubState();
}

class _ScreenB_SubState extends State<ScreenB_Sub> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Expanded(child: getTextScrollWidget()),
      ],
    );
  }
}
mark8044 commented 2 years ago

I fixed this in a fork (https://github.com/mark8044/PersistentBottomNavBar/tree/fix-scrolltotop), I also submitted a PR https://github.com/BilalShahid13/PersistentBottomNavBar/pull/295, but I think the package author is MIA. So for now you can use my fork and it should work

mark8044 commented 1 year ago

Looks like this was merged (THANK YOU!) so this should get closed @fushihara

fushihara commented 6 months ago

@mark8044 thankyou!