我想知道一旦按下按钮,是否有办法使sliverAppBar消失。不仅仅是滚动。
答案 0 :(得分:2)
是的,有可能。在下面的示例中查看。
import 'package:flutter/material.dart';
class Ch1 extends StatefulWidget {
@override
_Ch1State createState() => _Ch1State();
}
class _Ch1State extends State<Ch1> {
bool check = true;
@override
Widget build(BuildContext context) {
return Scaffold(
body: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
if(check)SliverAppBar(
expandedHeight: 200.0,
floating: false,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text("Collapsing Toolbar",
style: TextStyle(
color: Colors.white,
fontSize: 16.0,
)),
background: Image.network(
"https://images.pexels.com/photos/396547/pexels-photo-396547.jpeg?auto=compress&cs=tinysrgb&h=350",
fit: BoxFit.cover,
)),
),
];
} ,
body: Center(
child: InkWell(
onTap: (){
setState(() {
check= !check;
});
},
child: Text("Press"),
),
),
),
);
}
}