letsar / flutter_sticky_header

Flutter implementation of sticky headers for sliver
MIT License
907 stars 174 forks source link

Content scrolling under tab bar #72

Closed cedvdb closed 2 years ago

cedvdb commented 2 years ago

In the repro below the content is scrolling under the tab bar. I'm unsure this is a bug because the tab bar is set to have a collapsedSize of 0, However there is a bottom tab bar displayed and I think it should be taken into account. If there is a way to do this it is not exactly clear from the documentation either imo.

Repro

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  late final TabController tabController;

  @override
  void initState() {
    tabController = TabController(length: 2, vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return NestedScrollView(
      headerSliverBuilder: (context, innerBoxIsScrolled) => [
        SliverAppBar(
      collapsedHeight: 0,
      toolbarHeight: 0,
      pinned: true,
      expandedHeight: 250,
          bottom: TabBar(
            controller: tabController,
            tabs: const [
              Tab(text: 'A'),
              Tab(text: 'B'),
            ],
          ),
        ),
      ],
      body: TabBarView(
        controller: tabController,
        children: [
          SingleChildScrollView(
            child: MyTabView(),
          ),
          SingleChildScrollView(
            child: MyTabView(),
          ),
        ],
      ),
    );
  }
}

class MyTabView extends StatelessWidget {
  final List<Person> persons = [
    Person('Jack', age: 20),
    Person('John', age: 21),
//     Person('Doe', age: 25),
//     Person('Neil Young', age: 25),
//     Person('Joe rogan', age: 45),
//     Person('David Bowie', age: 45),
//     Person('Whatever', age: 45),
//     Person('Whatever', age: 45),
//     Person('Whatever', age: 45),
//     Person('Whatever', age: 45),
  ];

  MyTabView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        for (final person in persons)
          Card(
            child: Column(
              children: [
                ListTile(
                  title: const Text('name'),
                  trailing: Text(person.name),
                ),
                ListTile(
                  title: const Text('age'),
                  trailing: Text(person.age.toString()),
                ),
                ListTile(
                  title: const Text('male'),
                  trailing: Text(person.male.toString()),
                ),
              ],
            ),
          )
      ],
    );
  }
}

class Person {
  final String name;
  final bool male;
  final int age;
  Person(
    this.name, {
    required this.age,
    this.male = true,
  });
}
cedvdb commented 2 years ago

wrong repository