fujidaiti / smooth_sheets

Sheet widgets with smooth motion and great flexibility.
https://pub.dev/packages/smooth_sheets
MIT License
225 stars 22 forks source link

SheetDismissible not working with NavigationSheet #137

Closed Prymethron closed 5 months ago

Prymethron commented 5 months ago

In the AI Playlist Generator showcase, dismissible is working with SingleChildScrollView but when I tried this with routes I get this behaviour. But the thing is actually they should do the same.

Demo:

https://github.com/fujidaiti/smooth_sheets/assets/73065112/f95f4d9d-3623-47da-b412-8609e5a2979e

It looks like gesture is working but it's not ending with dissmissible state. So I couldn't figure out what I'm doing wrong.

Code:

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

void main() {
  runApp(const MaterialApp(
    home: HomePage(),
  ));
}

class HomePage extends StatelessWidget {
  const HomePage({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Smooth Sheets Example'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            BaseModal.show(context);
          },
          child: const Text('Show Modal'),
        ),
      ),
    );
  }
}

class BaseModal extends StatelessWidget {
  const BaseModal({super.key});

  static Future<dynamic> show(BuildContext context) async {
    return await Navigator.push(
        context,
        ModalSheetRoute(
          builder: (context) => const BaseModal(),
        ));
  }

  @override
  Widget build(BuildContext context) {
    final transitionObserver = NavigationSheetTransitionObserver();

    final nestedNavigator = Navigator(
      observers: [transitionObserver],
      onGenerateInitialRoutes: (navigator, initialRoute) {
        return [
          ScrollableNavigationSheetRoute(
            builder: (context) {
              return const BasePage();
            },
          ),
        ];
      },
    );

    return SafeArea(
      bottom: false,
      child: SheetDismissible(
        child: NavigationSheet(
          transitionObserver: transitionObserver,
          child: Material(
            color: Colors.white,
            clipBehavior: Clip.antiAlias,
            borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20)),
            child: nestedNavigator,
          ),
        ),
      ),
    );
  }
}

class BasePage extends StatelessWidget {
  const BasePage({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return SafeArea(
        top: false,
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            mainAxisSize: MainAxisSize.min,
            children: [
              Container(
                height: 300,
                color: Colors.amber,
              ),
              const SizedBox(
                height: 10,
              )
            ],
          ),
        ));
  }
}
fujidaiti commented 5 months ago

Hi @Prymethron,

Thanks for your report, and It seems like the drag-down-to-dismiss action doesn't work on a modal NavigationSheet with the versions of 0.5.x. As a workaround, you can use 0.4.x for a while.