我想知道是否有可能知道DraggableScrollableSheet在屏幕上占用了多少空间?我知道有minChildSize和maxChildSize,所以我假设在内部的某个地方存储了一个实际的分数值。有没有办法倾听这种价值观?
也许您可以使用NotificationListener及其方法onNotification来了解DraggableScrollableSheet的当前值。
import 'package:flutter/material.dart';
import 'package:payments/common/utils/colors.dart';
import 'package:payments/common/widgets/draggable_indicator.dart';
/// DraggableHistoryScreen class.
/// This class represents an screen for android and IOS
class DraggableHistoryScreen extends StatefulWidget{
final double initialChildSize;
/// Constructor method.
DraggableHistoryScreen({
required this.initialChildSize
});
@override
_DraggableHistoryScreenState createState() => _DraggableHistoryScreenState();
}
/// _DraggableHistoryScreenState class.
/// This class represents the state for [DraggableHistoryScreen]
class _DraggableHistoryScreenState extends State<DraggableHistoryScreen>{
@override
Widget build(BuildContext context) {
return Container(
child: NotificationListener<DraggableScrollableNotification>(
onNotification: (data) {
//Here the data of your DraggableScrollableSheet
print(data);
return true;
},
child: DraggableScrollableSheet(
maxChildSize: 1.0,
minChildSize: widget.initialChildSize,
initialChildSize: widget.initialChildSize,
builder: (context, scrollController) {
return Stack(
children: [
SingleChildScrollView(
controller: scrollController,
child: Container(
height:872.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(20.0),
topLeft: Radius.circular(20.0)),
color:AppColors.white_third_tone,
),
),
),
Align(
alignment: Alignment.topCenter,
child: DraggableIndicator())
],
);
},
),
)
);
}
}