抖动DraggableScrollableNotification到达屏幕的0.8

时间:2020-04-11 13:56:22

标签: flutter

在此代码中,我想在到达屏幕的0.8时触发DraggableScrollableNotification,这意味着我想知道DraggableScrollableNotification何时到达Appbar下,在我的代码中,我只能检测到当`DraggableScrollableNotification到达屏幕顶部时触发此操作和通知,我该如何解决此问题?

import 'package:flutter/material.dart';

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

class TeleBottomSheet extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'test',
      theme: ThemeData.light(),
      home: ShowTeleSheet(),
    );
  }
}

class ShowTeleSheet extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Stack(
          children: <Widget>[
            Container(
              margin: const EdgeInsets.only(top: kToolbarHeight),
              width:  double.infinity,
              height: double.infinity,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  RaisedButton(
                    child:Text('Click Here',style: TextStyle(color: Colors.black),),
                    onPressed: () {
                      showModalBottomSheet(
                        context: context,
                        isScrollControlled: true, // set this to true when using DraggableScrollableSheet as child
                        builder: (_) {
                          return NotificationListener<DraggableScrollableNotification>(
                            onNotification: (notification) {
                              if (notification.extent == 0.8) {
                                print('arrived under AppBar');
                              } else {
                              }
                              return true;
                            },
                            child: DraggableScrollableActuator(
                              child: DraggableScrollableSheet(
                                expand: false,
                                builder: (_, controller) {
                                  return Container(
                                    color: Colors.blue[500],
                                    child: ListView.builder(
                                      controller: controller, // provide DraggableScrollableSheet's ScrollController to ListView
                                      itemBuilder: (_, i) => ListTile(title: Text('Item $i')),
                                    ),
                                  );
                                },
                              ),
                            ),
                          );
                        },
                      );
                    },
                  ),
                ],
              ),
            ),
            Container(
              height: kToolbarHeight,
              child: Align(
                  alignment: Alignment.topCenter,
                  child: AppBar(
                    title: Text('test'),
                  )),
            )
          ],
        ),
      ),
    );
  }
}

0 个答案:

没有答案