akshathjain / sliding_up_panel

A draggable Flutter widget that makes implementing a SlidingUpPanel much easier!
https://pub.dartlang.org/packages/sliding_up_panel
Other
1.38k stars 381 forks source link

Using panelBuilder and header in a nested panel has odd behavior #181

Open Gigahawk opened 4 years ago

Gigahawk commented 4 years ago

Describe the bug The touch events on the header of a nested panel using a panelBuilder will get passed onto the parent panel.

To Reproduce Steps to reproduce the behavior:

Expected behavior Swiping down on the second panel header should always close the second panel, the first panel should not be affected. For context, I'm trying to reproduce something like this: https://youtu.be/0MCwl9CpYtg

Screenshots If applicable, add screenshots to help explain your problem.

Additional context My first thought was to (partially) fix it by using setState to make the first panel undraggable whenever the second one opens, however it seems that running setState will randomly cause the second panel to redraw as closed. https://www.dartpad.dev/0b8a550ced402e421d9f4e778ae95b6a

Smartphone (please complete the following information):

Sample main.dart Please provide a sample main.dart that reproduces this issue. The code provided here should be able to be run on its own without any external dependencies.

import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';
import 'dart:math';
import 'package:flutter/physics.dart';

final Color darkBlue = Color.fromARGB(255, 18, 32, 47);

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: SlidingUpPanel(
          maxHeight: 400,
          body: Center(child: Text("Base View")),
          panel: SlidingUpPanel(
            maxHeight: 350,
            body: Container(
              color: Colors.red,
              child: Text("First Panel")
            ),
            header: Container(
              width: 100.0,
              height: 100.0,
              color: Colors.green,
              child: Text("Second Panel Header"),
            ),
            panelBuilder: (sc) {
              return ListView.builder(
                itemCount: 100,
                controller: sc,
                itemBuilder: (context, idx) {
                  return Container(
                    color: Colors.blue,
                    height: 50.0,
                    child: Text("$idx")
                  );
                }
              );
            }
          )

        )
      ),
    );
  }
}
Gigahawk commented 4 years ago

I'm guessing this has something to do with the panelBuilder using a Listener which somehow doesn't properly consume the touch event when dragging the header, so it gets passed onto the panel below.