栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Flutter如何检查Sliver AppBar是展开还是折叠?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Flutter如何检查Sliver AppBar是展开还是折叠?

您可以使用LayoutBuilder获得Sliver AppBar的最大高度。当maximum.height = 80.0时,实际上意味着条子appbar被折叠。

这是一个完整的示例:

import 'package:flutter/material.dart';void main() => runApp(MaterialApp(      home: MyApp(),    ));class MyApp extends StatefulWidget {  @override  _MyAppState createState() => _MyAppState();}class _MyAppState extends State<MyApp> {  var top = 0.0;  @override  Widget build(BuildContext context) {    return Scaffold(        body: NestedScrollView(      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {        return <Widget>[          SliverAppBar(   expandedHeight: 200.0,   floating: false,   pinned: true,   flexibleSpace: LayoutBuilder(       builder: (BuildContext context, BoxConstraints constraints) {     // print('constraints=' + constraints.toString());     top = constraints.biggest.height;     return FlexibleSpaceBar(         centerTitle: true,         title: AnimatedOpacity(  duration: Duration(milliseconds: 300),  //opacity: top == 80.0 ? 1.0 : 0.0,  opacity: 1.0,  child: Text(    top.toString(),    style: TextStyle(fontSize: 12.0),  )),         background: Image.network("https://images.unsplash.com/photo-1542601098-3adb3baeb1ec?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=5bb9a9747954cdd6eabe54e3688a407e&auto=format&fit=crop&w=500&q=60",fit: BoxFit.cover,         ));   })),        ];      },body: ListView.builder(        itemCount: 100,        itemBuilder: (context,index){          return Text("List Item: " + index.toString());        },      ),    ));  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/368988.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号