Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SheetDismissible not working with infinite looping scroll widget #80

Closed
naamapps opened this issue Mar 29, 2024 · 3 comments · Fixed by #138
Closed

SheetDismissible not working with infinite looping scroll widget #80

naamapps opened this issue Mar 29, 2024 · 3 comments · Fixed by #138
Assignees
Labels
bug Something isn't working P1

Comments

@naamapps
Copy link

naamapps commented Mar 29, 2024

Hi,
Maybe I didn't do it correctly, but I stumbled into problems when using ScrollableSheet.

  1. When the scrollable initially can be scrolled upwards, the sheet thinks I want to close it, but I want to scroll up. The sheet corrects itself when scrolling down and then up, but there is another problem that occurs now.. ->
  2. The sheet cannot be dismissed when using ScrollableSheet & SheetDismissible when the scrollable widget is scrolled & wrapping the header in SheetDraggable + putting the finger on the header Text and not the space around it.

See here:

Screen_Recording_20240329_174700.mp4

Code:

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:smooth_sheets/smooth_sheets.dart';

class SheetShape extends StatelessWidget {
  final Widget child;
  const SheetShape({super.key, required this.child});

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Card(
        color: Theme.of(context).bottomSheetTheme.backgroundColor,
        elevation: 0,
        clipBehavior: Clip.antiAlias,
        margin: const EdgeInsets.only(left: 15, right: 15, bottom: 3, top: 3),
        shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(36)),
        ),
        child: child,
      ),
    );
  }
}

class StaticSheetContent extends StatelessWidget {
  final bool includeShape;
  final Widget? header;
  final Widget? body;
  final Widget? footer;
  final bool isScrollableSheet;
  const StaticSheetContent({
    super.key,
    this.body,
    this.header,
    this.footer,
    this.includeShape = true,
    this.isScrollableSheet = false,
  });

  @override
  Widget build(BuildContext context) {
    final content = Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        if (header != null) header!,
        if (body != null)
          Expanded(
            flex: isScrollableSheet ? 1 : 0,
            child: Padding(
              padding: const EdgeInsets.symmetric(vertical: 10),
              child: body,
            ),
          ),
        if (footer != null) footer!,
      ],
    );

    if (includeShape) {
      return SheetShape(
        child: content,
      );
    }

    return content;
  }
}

Future<void> showTimeSheet(BuildContext context) async {
  final now = DateTime.now();
  var newDateTime = DateTime.now();

  final modalRoute = ModalSheetRoute(
    transitionDuration: const Duration(milliseconds: 250),
    builder: (context) => SheetDismissible(
      child: ScrollableSheet(
        child: StaticSheetContent(
          header: const SheetDraggable(
            child: Column(
              children: [
                SizedBox(height: 24),
                Padding(
                  padding: EdgeInsets.symmetric(
                    horizontal: 24,
                  ),
                  child: Text('Pick a time'),
                ),
              ],
            ),
          ),
          body: SizedBox(
            height: 250,
            child: CupertinoTheme(
              data: const CupertinoThemeData(
                textTheme: CupertinoTextThemeData(
                  dateTimePickerTextStyle: TextStyle(
                    fontSize: 40,
                  ),
                ),
              ),
              child: CupertinoDatePicker(
                initialDateTime: now,
                mode: CupertinoDatePickerMode.time,
                use24hFormat: MediaQuery.alwaysUse24HourFormatOf(context),
                onDateTimeChanged: (value) {
                  HapticFeedback.selectionClick();
                  newDateTime = value;
                },
                itemExtent: 80,
              ),
            ),
          ),
        ),
      ),
    ),
  );
  await Navigator.push(context, modalRoute);
}
@fujidaiti
Copy link
Owner

fujidaiti commented Mar 30, 2024

It seems like those problems are caused by the logic used to detect when to start the drag-down-
to-dismiss-sheet action of SheetDismissible. First, if the sheet has a scrollable widget, the SheetDismissible does not invoke the action while the scrollable widget can be scrolled down, and for the second problem, it never starts the action because the picker can be scrolled down infinitely. For the first problem, the SheetDismissible starts the action even though the picker can be scrolled down, because it has no information at first build about how many pixels the scrollable widget can be scrolled down.

Workaround

Unfortunately, there is no easy way to workaround these issues. For now, please remove SheetDismissible to disable the drag-down-to-dismiss behavior until the bug is fixed.

P.S.

The ScrollableSheet won't work with the date picker because it is an infinite looping scroll widget and it's unclear when to start dragging up/down the sheet. I'd recommend using the DraggableSheet instead.

@fujidaiti fujidaiti changed the title Problems with ScrollableSheet Problems with modal sheet and infinite scroll widget Mar 30, 2024
@fujidaiti fujidaiti changed the title Problems with modal sheet and infinite scroll widget Problems with modal sheet and infinite looping scroll widget Mar 30, 2024
@fujidaiti fujidaiti added bug Something isn't working P2 labels Mar 30, 2024
@fujidaiti fujidaiti changed the title Problems with modal sheet and infinite looping scroll widget SheetDismissible not working with infinite looping scroll widget Mar 30, 2024
@fujidaiti fujidaiti self-assigned this Mar 30, 2024
@fujidaiti fujidaiti added P2 and removed P2 labels Apr 1, 2024
@naamapps
Copy link
Author

naamapps commented Apr 2, 2024

I'm not sure if it's only for infinite scroll widgets but also for scrolling widgets that the initial scroll offset is not zero (could be at the middle of the list initially) and then when trying to scroll down it would still dismiss the sheet instead of scrolling.
Need to test it though.

@fujidaiti
Copy link
Owner

fujidaiti commented Apr 2, 2024

but also for scrolling widgets that the initial scroll offset is not zero

I think so, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants