Skip to content

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

Open
@srkrishnan1989

Description

@srkrishnan1989

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');
              },
            ),
          )),
    );
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions