Flutter 在DragableScrollableSheet颤振中设置childSize的位置
我正在尝试设置DragableScrollableSheet的动画,这样当用户在通知.范围上的任何位置松开滚动时,该栏(或称为弹出窗口?)将设置为最小儿童大小或最大儿童大小(范围接近)。像这样使用的应用程序的一个例子是Airbnb 以下是我到目前为止的编码:Flutter 在DragableScrollableSheet颤振中设置childSize的位置,flutter,dart,Flutter,Dart,我正在尝试设置DragableScrollableSheet的动画,这样当用户在通知.范围上的任何位置松开滚动时,该栏(或称为弹出窗口?)将设置为最小儿童大小或最大儿童大小(范围接近)。像这样使用的应用程序的一个例子是Airbnb 以下是我到目前为止的编码: import 'dart:ui'; import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends State
import 'dart:ui';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Tips',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
double _percent = 0.0;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors. deepPurple.shade600,
body: Stack(
children: [
Container(
width: 400,
height: 600,
child: Image.asset(
"assets/diamond.png",
fit: BoxFit.contain,
),
),
Positioned(
child: Text(
"Todos",
style: TextStyle(
color: Colors.white,
fontSize: 40,
),
),
top: 40,
left: 20,
),
Positioned.fill(
child: NotificationListener<DraggableScrollableNotification>(
onNotification: (notification) {
setState(() {
_percent = ((10 * notification.extent)/9) - (1/9);
});
return true;
},
child: DraggableScrollableSheet(
minChildSize: 0.1,
initialChildSize: 0.1,
maxChildSize: 1.0,
builder: (BuildContext c, s){
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
topLeft: Radius.circular(20),
),
),
child: MediaQuery.removePadding(
context: context,
removeTop: true,
child: ListView(
controller: s,
children: [
SizedBox(
height: 6,
),
Center(
child: Container(
height: 6,
width: 50,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.circular(5),
),
),
),
Center(
child: Container(
height: MediaQuery.of(context).size.height/10,
width: MediaQuery.of(context).size.width ,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
"300 store nearby",
style: TextStyle(
color: Colors.black,
),
),
),
),
),
SizedBox(
height: 20,
),
],
),
),
);
},
),
),
),
],
),
);
}
}
导入“dart:ui”;
进口“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振提示”,
主题:主题数据(
主样本:颜色。蓝色,
),
主页:MyHomePage(),
);
}
}
类MyHomePage扩展StatefulWidget{
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
双百分比=0.0;
@凌驾
小部件构建(构建上下文){
返回脚手架(
背景颜色:Colors.deepPurple.shade600,
主体:堆栈(
儿童:[
容器(
宽度:400,
身高:600,
子:Image.asset(
“assets/diamond.png”,
适合:BoxFit.contain,
),
),
定位(
子:文本(
“待办事项”,
样式:TextStyle(
颜色:颜色,白色,
尺寸:40,
),
),
前40名,
左:20,,
),
定位填充(
孩子:NotificationListener(
通知:(通知){
设置状态(){
_百分比=((10*通知范围)/9)-(1/9);
});
返回true;
},
子项:DragableScrollableSheet(
minChildSize:0.1,
initialChildSize:0.1,
maxChildSize:1.0,
生成器:(BuildContext c,s){
返回容器(
装饰:盒子装饰(
颜色:颜色,白色,
borderRadius:仅限borderRadius(
右上角:半径。圆形(20),
左上:半径。圆形(20),
),
),
子项:MediaQuery.removePadding(
上下文:上下文,
removeTop:没错,
子:ListView(
控制员:s,,
儿童:[
大小盒子(
身高:6,
),
居中(
子:容器(
身高:6,
宽度:50,
装饰:盒子装饰(
颜色:颜色。灰色,
边界半径:边界半径。圆形(5),
),
),
),
居中(
子:容器(
高度:MediaQuery.of(context).size.height/10,
宽度:MediaQuery.of(context).size.width,
装饰:盒子装饰(
边界半径:边界半径。圆形(10),
),
儿童:中心(
子:文本(
“300店附近”,
样式:TextStyle(
颜色:颜色,黑色,
),
),
),
),
),
大小盒子(
身高:20,
),
],
),
),
);
},
),
),
),
],
),
);
}
}