Flutter 如何在颤振中创建这种类型的对话框
我正在创建一个故事应用程序,两个用户在下面的图片中这样讲述故事。所以这里我想创建一个对话框,如下图所示。但我不知道如何创造Flutter 如何在颤振中创建这种类型的对话框,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,我正在创建一个故事应用程序,两个用户在下面的图片中这样讲述故事。所以这里我想创建一个对话框,如下图所示。但我不知道如何创造 您应该按照下面的方式执行 class IntroPage extends StatefulWidget { @override State<StatefulWidget> createState() => _IntroPageState(); } class _IntroPageState extends State<IntroPage&g
您应该按照下面的方式执行
class IntroPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _IntroPageState();
}
class _IntroPageState extends State<IntroPage>
with SingleTickerProviderStateMixin {
AnimationController animationController;
bool _menuShown = false;
@override
void initState() {
animationController =
AnimationController(vsync: this, duration: Duration(milliseconds: 500));
super.initState();
}
@override
Widget build(BuildContext context) {
Animation opacityAnimation =
Tween(begin: 0.0, end: 1.0).animate(animationController);
if (_menuShown)
animationController.forward();
else
animationController.reverse();
return Scaffold(
backgroundColor: Colors.amberAccent,
body: Stack(
overflow: Overflow.visible,
children: <Widget>[
Positioned(
right: 0,
top:90,
child: InkWell(
onTap: () {
setState(() {
_menuShown = !_menuShown;
});
},
child: Image.asset(
'assets/images/girls.png',
height: 250,
),
),
),
Positioned(
child: FadeTransition(
opacity: opacityAnimation,
child: _DialogUI(),
),
right: 40.0,
top: 300.0,
),
],
),
);
}
}
class _DialogUI extends StatelessWidget {
_DialogUI();
final double padding = 8.0;
@override
Widget build(BuildContext context) {
return Center(
child: Material(
clipBehavior: Clip.antiAlias,
shape: _DialogShapeBorder(
borderRadius: BorderRadius.all(Radius.circular(padding)),
padding: padding),
elevation: 4.0,
child: Container(
margin: const EdgeInsets.all(10),
padding: EdgeInsets.all(padding).copyWith(bottom: padding * 2),
child: Center(
child: Text(
'Filler text is text that shares \nsome characteristics of a real written text, \n but is random or otherwise generated.\n It may be used to display a sample of fonts,\n generate text for testing, or to spoof an e-mail spam filter.'),
),
)),
);
}
}
class _DialogShapeBorder extends RoundedRectangleBorder {
_DialogShapeBorder({
@required this.padding,
side = BorderSide.none,
borderRadius = BorderRadius.zero,
}) : super(side: side, borderRadius: borderRadius);
final double padding;
@override
Path getOuterPath(Rect rect, {TextDirection textDirection}) {
return Path()
..moveTo(rect.width - 18.0, rect.top)
..lineTo(rect.width - 20.0, rect.top - 36.0)
..lineTo(rect.width - 52.0, rect.top)
..addRRect(borderRadius.resolve(textDirection).toRRect(Rect.fromLTWH(
rect.left, rect.top, rect.width, rect.height - padding)));
}
}
class IntroPage扩展StatefulWidget{
@凌驾
State createState()=>\u IntroPageState();
}
类_IntroPageState扩展状态
使用SingleTickerProviderStateMixin{
动画控制器;
bool\u menuShown=false;
@凌驾
void initState(){
动画控制器=
AnimationController(vsync:this,duration:duration(毫秒:500));
super.initState();
}
@凌驾
小部件构建(构建上下文){
动画不透明动画=
吐温(开始:0.0,结束:1.0)。动画(animationController);
如果(_menuShown)
animationController.forward();
其他的
animationController.reverse();
返回脚手架(
背景颜色:Colors.amberAccent,
主体:堆栈(
溢出:溢出。可见,
儿童:[
定位(
右:0,,
排名:90,
孩子:InkWell(
onTap:(){
设置状态(){
_menuShown=!\u menuShown;
});
},
子:Image.asset(
“assets/images/girls.png”,
身高:250,
),
),
),
定位(
孩子:FadeTransition(
不透明度:不透明图像,
子项:_DialogUI(),
),
右图:40.0,
top:300.0,
),
],
),
);
}
}
类_DialogUI扩展了无状态小部件{
_DialogUI();
最终双填充=8.0;
@凌驾
小部件构建(构建上下文){
返回中心(
儿童:材料(
clipBehavior:Clip.antiAlias,
形状:\ u对话框形状顺序(
borderRadius:borderRadius.all(半径.圆形(填充)),
填充:填充),
标高:4.0,
子:容器(
边距:常数边集全部(10),
padding:EdgeInsets.all(padding).copyWith(底部:padding*2),
儿童:中心(
子:文本(
'填充文本是共享\n真实书面文本某些特征的文本,\n但它是随机的或以其他方式生成的。\n它可用于显示字体样本,\n生成测试文本,或欺骗电子邮件垃圾邮件过滤器。'),
),
)),
);
}
}
类_对话框ShapeOrder扩展RoundedRectangleBorder{
_对话框形状排序器({
@需要这个。填充,
side=BorderSide.none,
borderRadius=borderRadius.0,
}):super(边:边,边界半径:边界半径);
最终双重填充;
@凌驾
路径getOuterPath(Rect Rect,{TextDirection TextDirection}){
返回路径()
..移动到(矩形宽度-18.0,矩形顶部)
..lineTo(矩形宽度-20.0,矩形顶部-36.0)
..直线至(直线宽度-52.0,直线顶部)
..addrect(边界半径.解析(文本方向).toRRect(Rect.fromLTWH(
rect.left、rect.top、rect.width、rect.height-padding);
}
}
输出
像这样的事情怎么样:不,伙计,这对我不起作用