fujidaiti / smooth_sheets

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

Snapping effect doesn't work when closing keyboard on non-fullscreen sheet #192

Open fujidaiti opened 1 month ago

fujidaiti commented 1 month ago

Thank you for your response and the suggestion to use SheetContentScaffold. However, the issue still persists, the sheet still partially moves up when the keyboard opens. I also noted your comment about avoiding nesting a sheet within a Scaffold, so I removed the scaffold from the root.

Here is the updated code I used:

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

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: SmoothSheetDemo(),
    );
  }
}

class SmoothSheetDemo extends StatefulWidget {
  const SmoothSheetDemo({super.key});

  @override
  _SmoothSheetDemoState createState() => _SmoothSheetDemoState();
}

class _SmoothSheetDemoState extends State<SmoothSheetDemo> {
  final SheetController _smoothSheetController = SheetController();

  @override
  Widget build(BuildContext context) {
    final List<double> snaps = [0.3, 0.5, 1.0];
    const minExtent = Extent.proportional(0.3);
    final extentSnaps = snaps.map((e) => Extent.proportional(e)).toList();
    final physics = SnappingSheetPhysics(
      snappingBehavior: SnapToNearest(
        snapTo: extentSnaps,
      ),
    );

    return SafeArea(
      child: Stack(
        children: [
          const Scaffold(
            body: Column(
              children: [
                TextField(),
                Expanded(
                  child: Placeholder(),
                )
              ],
            ),
            resizeToAvoidBottomInset: false,
          ),
          DraggableSheet(
            minExtent: minExtent,
            controller: _smoothSheetController,
            initialExtent: minExtent,
            physics: physics,
            child: SheetContentScaffold(
              body: buildContent(),
            ),
          ),
        ],
      ),
    );
  }

  Widget buildContent() {
    return Container(
      color: Colors.grey[900],
      child: Column(
        children: [
          const SizedBox(height: 16),
          const TextField(),
          const SizedBox(height: 16),
          Expanded(
            child: ListView(
              children: List.generate(
                100,
                (index) => Container(
                  margin: const EdgeInsets.all(4),
                  child: const FlutterLogo(),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

_Originally posted by @faizanje in https://github.com/fujidaiti/smooth_sheets/issues/184#issuecomment-2197356152_

fujidaiti commented 1 month ago

Screen_recording_20240628_221948.webm

Orignilally posted in https://github.com/fujidaiti/smooth_sheets/issues/184#issuecomment-2197359749