飞镖 – 如何在颤动中制作全屏幕对话框?

飞镖 – 如何在颤动中制作全屏幕对话框?,第1张

概述我想制作一个全屏对话框.对话框背景必须是不透明的. 这是一个例子: 如何在Flutter中制作这样的? 您可以使用导航器推送半透明的 ModalRoute: import 'package:flutter/material.dart';class TutorialOverlay extends ModalRoute<void> { @override Duration get tran 我想制作一个全屏对话框.对话框背景必须是不透明的.
这是一个例子:

如何在Flutter中制作这样的?

解决方法 您可以使用导航器推送半透明的 ModalRoute

import 'package:Flutter/material.dart';class Tutorialoverlay extends ModalRoute<voID> {  @overrIDe  Duration get TransitionDuration => Duration(milliseconds: 500);  @overrIDe  bool get opaque => false;  @overrIDe  bool get barrIErdismissible => false;  @overrIDe  color get barrIErcolor => colors.black.withOpacity(0.5);  @overrIDe  String get barrIErLabel => null;  @overrIDe  bool get maintainState => true;  @overrIDe  Widget buildPage(      BuildContext context,Animation<double> animation,Animation<double> secondaryAnimation,) {    // This makes sure that text and other content follows the material style    return Material(      type: MaterialType.transparency,// make sure that the overlay content is not cut off      child: SafeArea(        child: _buildOverlayContent(context),),);  }  Widget _buildOverlayContent(BuildContext context) {    return Center(      child: Column(        mainAxisSize: MainAxisSize.min,children: <Widget>[          Text(            'This is a nice overlay',style: TextStyle(color: colors.white,FontSize: 30.0),Raisedbutton(            onpressed: () => Navigator.pop(context),child: Text('dismiss'),)        ],);  }  @overrIDe  Widget buildTransitions(      BuildContext context,Widget child) {    // You can add your own animations for the overlay content    return FadeTransition(      opacity: animation,child: ScaleTransition(        scale: animation,child: child,);  }}// Example application:voID main() => runApp(MyApp());class MyApp extends StatelessWidget {  @overrIDe  Widget build(BuildContext context) {    return MaterialApp(      Title: 'Flutter Playground',home: TestPage(),);  }}class TestPage extends StatelessWidget {  voID _showOverlay(BuildContext context) {    Navigator.of(context).push(Tutorialoverlay());  }  @overrIDe  Widget build(BuildContext context) {    return Scaffold(      appbar: Appbar(Title: Text('Test')),body: padding(        padding: EdgeInsets.all(16.0),child: Center(          child: Raisedbutton(            onpressed: () => _showOverlay(context),child: Text('Show Overlay'),);  }}
总结

以上是内存溢出为你收集整理的飞镖 – 如何在颤动中制作全屏幕对话框?全部内容,希望文章能够帮你解决飞镖 – 如何在颤动中制作全屏幕对话框?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1003454.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存