描述:
调用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')),
);
},
),
);
},
))
],
);
},
),
),
);
}
}