Dolphin
Dolphin

Reputation: 38631

how to hide appbar when CustomScrollView scroll in flutter

I am using flutter to show some html page, is it possbile to hide the appBar when CustomScrollView scroll up? Then I could have more screen area to show the html content. This is my current code snippnet:

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_icons/flutter_icons.dart';
import 'package:Cruise/src/component/comment_list.dart';
import 'package:Cruise/src/component/story_information.dart';
import 'package:Cruise/src/models/Item.dart';
import 'package:Cruise/src/common/Repo.dart';

class StoryPage extends HookWidget {
  const StoryPage({
    Key key,
    @required this.item,
  }) : super(key: key);

  final Item item;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Cruise'),
        actions: [
          if (item.parent != null)
            IconButton(
              icon: Icon(Feather.corner_left_up),
              onPressed: () async {
                Item parent = await Repo.fetchItem(item.parent);
                Navigator.push(
                  context,
                  MaterialPageRoute(
                      builder: (context) => StoryPage(item: parent)),
                );
              },
            ),
        ],
      ),
      body: CustomScrollView(
        slivers: [
          SliverToBoxAdapter(child: StoryInformation(item: item)),
          CommentList(item: item)
        ],
      ),
    );
  }
}

Upvotes: 2

Views: 576

Answers (1)

ajay
ajay

Reputation: 1000

You can use SliverChildBuilderDelegate to achieve this,

SliverChildBuilderDelegate class

Scaffold(
      body: CustomScrollView(
        slivers: <Widget>[
          SliverAppBar(
            title: Text('data'),
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate(
                (context, index) => Text(
                      index.toString(),
                    ),
                childCount: 300),
          ),
        ],
      ),
    );

Upvotes: 2

Related Questions