通常、SliverList を下にスライドすると、フローティング SliverAppBar が SliverList の上層に表示されます。
ただし、 の値を に変更するshrinkWrap
と、またはの要素の下に が表示されtrue
ます。SliverAppBar
SliverList
SliverGrid
この問題を解決するにはどうすればよいですか?
コードは次のとおりです。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return CustomScrollView(
shrinkWrap: false,
slivers: <Widget>[
const SliverAppBar(
pinned: false,
floating: true,
flexibleSpace: FlexibleSpaceBar(
title: Text('SliverAPPBar'),
),
),
SliverGrid.count(
crossAxisCount: 3,
children: [
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.red, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.purple, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.green, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.orange, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.yellow, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.pink, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.cyan, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.indigo, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.blue, height: 150.0),
),
],
),
SliverList(
delegate: SliverChildListDelegate(
[
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.pink, height: 100.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.cyan, height: 100.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.indigo, height: 100.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.blue, height: 100.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.yellow, height: 100.0),
),
],
),
),
SliverFixedExtentList(
itemExtent: 150.0,
delegate: SliverChildListDelegate(
[
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.red, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.purple, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.green, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.orange, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.yellow, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.pink, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.cyan, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.indigo, height: 150.0),
),
Padding(
padding: EdgeInsets.only(left: 24.0, right: 24.0),
child: Container(color: Colors.blue, height: 150.0),
),
],
),
),
],
);
}
}