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

[scrollable_positioned_list] Positioned with appbar on NestedScrollView / SliverAppBar ,Appbar is not hiding #407

Open
srkrishnan1989 opened this issue Jul 26, 2022 · 2 comments

Comments

@srkrishnan1989
Copy link

In Android app ,

NestedScrollView / SliverAppBar, ,Appbar is not hiding

code sample
import 'package:flutter/material.dart';

import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';

class ScrollablePositionedDemo extends StatefulWidget {
  const ScrollablePositionedDemo({Key? key}) : super(key: key);

  @override
  State<ScrollablePositionedDemo> createState() =>
      _ScrollablePositionedDemoState();
}

class _ScrollablePositionedDemoState extends State<ScrollablePositionedDemo> {
  late bool scrolltbutton;
  bool scrolllockbutton = false;
  late double sleft;
  late double stop;

  final scrollDirection = Axis.vertical;

  final ItemScrollController itemScrollController = ItemScrollController();
  final ItemPositionsListener itemPositionsListener =
      ItemPositionsListener.create();

  List<String> dataList = [
    "2K",
    "86-DOS",
    "A/UX",
    "Acados",
    "ACP (Airline Control Program)",
    "AdaOS",
    "ADMIRAL",
    "Adrenaline",
    "aerolitheOS",
    "Aimos",
    "AIOS",
    "AIX",
    "Allegro",
    "AllianceOS",
  ];
  @override
  void initState() {
    super.initState();
    initposition();
  }

  initposition() {
    sleft = 110;
    stop = 100;
  }

  sentback() {
    Navigator.of(context).pop();
  }

  Widget scrolllockappbutton() {
    return IconButton(
        icon: scrolllockbutton
            ? const Icon(Icons.lock, color: Colors.red, size: 25)
            : const Icon(Icons.lock_open_sharp, color: Colors.green, size: 25),
        onPressed: () {
          setState(() {
            scrolllockbutton = !scrolllockbutton;
          });
        }
        //)
        );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(children: [
        NestedScrollView(
          // controller: ancon,
          floatHeaderSlivers: true,
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            return <Widget>[
              SliverAppBar(
                snap: true,
                pinned: false,
                floating: true,
                title: const Text("Demo"),
                actions: <Widget>[
                  scrolllockappbutton(),
                ],
              ),
            ];
          },
          body:
              // child:
              Column(
            children: [
              Expanded(
                child: ScrollablePositionedList.builder(
                    itemScrollController: itemScrollController,
                    itemPositionsListener: itemPositionsListener,
                    itemCount: dataList.length,
                    itemBuilder: (context, index) {
                      return Column(children: [
                        ListTile(
                          title: Text(
                            '\n${dataList[index]}',
                            style: const TextStyle(fontSize: 50),
                          ),
                          onTap: () {
                            print('object');
                          },
                        ),
                        const Divider(
                          height: 1,
                          color: Colors.grey,
                        )
                      ]);
                    }),
              ),
            ],
          ),
          // ),
        ),
        Positioned(
          left: sleft,
          top: stop,
          child: scrolllockbutton
              ? showbutton()
              : Draggable(
                  feedback: showbutton(),
                  child: showbutton(),
                  onDragEnd: (drag) {
                    final renderbox = context.findRenderObject() as RenderBox;
                    Offset off = renderbox.globalToLocal(drag.offset);
                    setState(() {
                      stop = off.dy - 55;
                      sleft = off.dx + 5;
                    });
                  },
                ),
        ),
      ]),
    );
  }

  showbutton() {
    return Material(
      child: ClipRRect(
          borderRadius: BorderRadius.circular(5.0),
          child: Container(
            color: Colors.red.shade100,
            child: IconButton(
              color: Colors.blue,
              icon: const Icon(Icons.add_a_photo),
              onPressed: () {
                print('showbutton');
              },
            ),
          )),
    );
  }
}
@lpongetti
Copy link

+1

@blok5025
Copy link

blok5025 commented Mar 4, 2023

This can be solved with #445 . Although, you have to wrap the ScrollablePositionedList with DraggableScrollableSheet for it to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants