0
点赞
收藏
分享

微信扫一扫

Flutter详解DraggableScrollableActuator

惠特曼 2022-03-26 阅读 49
flutter

描述:

调用DraggableScrollableActuator.reset(context)方法,通知子控件DraggableScrollableSheet位置到初始化状态

效果图:

 代码:

import 'package:flutter/material.dart';

class DraggableScrollableActuatorPage extends StatefulWidget {
  const DraggableScrollableActuatorPage({Key? key}) : super(key: key);

  @override
  State<DraggableScrollableActuatorPage> createState() =>
      _DraggableScrollableActuatorPageState();
}

class _DraggableScrollableActuatorPageState
    extends State<DraggableScrollableActuatorPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("DraggableScrollableActuator")),
      body: DraggableScrollableActuator(
        child: Builder(
          builder: (context) {
            return Column(
              children: [
                ElevatedButton(
                  onPressed: () {
                    DraggableScrollableActuator.reset(context);
                  },
                  child: const Text('reset'),
                ),
                Expanded(child: DraggableScrollableSheet(
                  builder: (BuildContext context,
                      ScrollController scrollController) {
                    return Container(
                      color: Colors.teal[100],
                      child: ListView.builder(
                        controller: scrollController,
                        itemCount: 20,
                        itemBuilder: (BuildContext context, int index) {
                          return ListTile(
                            title: Center(child: Text('$index')),
                          );
                        },
                      ),
                    );
                  },
                ))
              ],
            );
          },
        ),
      ),
    );
  }
}
举报

相关推荐

0 条评论