如何使用手势检测器以及如何创建可拖动的顶栏

问题描述 投票:0回答:1

当我尝试在我的应用程序中创建一个像顶部栏的Android状态栏时,我使用手势检测器,但我不知道如何继续它。如何在上方隐藏容器并在如下滑动时获取容器:

enter image description here

在滑动结束并测量滑动距离后如何执行某些操作。顶部栏应该安静下来,而不是留在中间。我如何设置动画以使其与现在的方式类似。我尝试了onVerticalDrag等,但我不知道如何做到这一点。

dart flutter
1个回答
0
投票

Flutter Slivers可以为您做到这一点。

检查以下代码:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body:NestedScrollView(
          headerSliverBuilder: (BuildContext context, bool _) {
            return <Widget>[
              SliverAppBar(
                expandedHeight: 200.0,
                floating: true,
                pinned: true,
                snap: true,
                flexibleSpace: FlexibleSpaceBar(
                  centerTitle: true,
                  title: Text("Collapsing Toolbar",
                    style: TextStyle(
                      color: Colors.white,
                      fontSize: 16.0,
                    ),
                  ),
                ),
              ),
            ];
          },
          body: Center(
            child: Text("My Fancy Text"),
          ),
        ),
      ),
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.