欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Flutter自定義彈窗Dialog效果

 更新時間:2022年03月23日 15:09:29   作者:antu58  
這篇文章主要為大家詳細(xì)介紹了Flutter自定義彈窗Dialog效果,含底部抽屜,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Flutter自定義彈窗Dialog效果的具體代碼,供大家參考,具體內(nèi)容如下

主要是基于系統(tǒng)的dialog機(jī)制做一些使用限制和自定義UI的優(yōu)化

核心代碼:

class CustomDialog {
?
? static void show(BuildContext context, Widget Function(BuildContext ctx, void Function() dismiss)builder, {bool cancellable = false}) {
? ? showDialog(
? ? ? context: context,
? ? ? barrierDismissible: cancellable,
? ? ? builder: (ctx) {
? ? ? ? return WillPopScope(
? ? ? ? ? child: Dialog(
? ? ? ? ? ? child: builder(ctx, () => Navigator.of(ctx).pop()),
? ? ? ? ? ? backgroundColor: Colors.transparent,
? ? ? ? ? ? shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(0.0))),
? ? ? ? ? ? elevation: 0,
? ? ? ? ? ? alignment: Alignment.center,
? ? ? ? ? ),
? ? ? ? ? onWillPop: () async => cancellable,
? ? ? ? );
? ? ? },
? ? );
? }
?
?
? static void showBottomSheet(BuildContext context, Widget Function(BuildContext ctx, void Function() dismiss)builder, {bool cancellable = true}) {
?
? ? showModalBottomSheet(
? ? ? context: context,
? ? ? isDismissible: cancellable,
? ? ? enableDrag: cancellable,
? ? ? isScrollControlled: true,
? ? ? builder: (BuildContext ctx) {
? ? ? ? return WillPopScope(
? ? ? ? ? child: builder(ctx, () => Navigator.of(ctx).pop()),
? ? ? ? ? onWillPop: () async => cancellable,
? ? ? ? );
? ? ? },
? ? ? //不設(shè)置會默認(rèn)使用屏幕最大寬度而不是子組件寬度
? ? ? constraints: const BoxConstraints(minWidth: 0, minHeight: 0, maxWidth: double.infinity, maxHeight: double.infinity),
? ? ? backgroundColor: Colors.transparent,
? ? );
? }
}

使用:

import 'dart:async';
import 'package:flutter/material.dart';
?
class DialogTestPage extends StatefulWidget {
? const DialogTestPage({Key? key}) : super(key: key);
?
? @override
? State<StatefulWidget> createState() => _DialogTestState();
}
?
class _DialogTestState extends State<DialogTestPage> {
? @override
? Widget build(BuildContext context) {
?
? ? return Scaffold(
? ? ? body: Column(children: [
? ? ? ? const SizedBox(height: 0, width: double.infinity,),
? ? ? ? TextButton(
? ? ? ? ? child: const Text("show dialog"),
? ? ? ? ? onPressed: () => showCustomDialog(),
? ? ? ? ),
? ? ? ? TextButton(
? ? ? ? ? child: const Text("show delay dialog"),
? ? ? ? ? onPressed: () => showDelayDialog(),
? ? ? ? ),
? ? ? ? TextButton(
? ? ? ? ? child: const Text("show sheet"),
? ? ? ? ? onPressed: () => showSheetDialog(),
? ? ? ? ),
? ? ? ], mainAxisAlignment: MainAxisAlignment.spaceAround, crossAxisAlignment: CrossAxisAlignment.center,),
? ? );
? }
?
?
? void showCustomDialog() {
? ? CustomDialog.show(context, (context, dismiss) {
? ? ? return Container(
? ? ? ? width: 200,
? ? ? ? height: 100,
? ? ? ? color: Colors.white,
? ? ? ? child: Center(child: TextButton(onPressed: () => dismiss(), child: const Text("POP")),),
? ? ? );
? ? });
? }
?
? void showSheetDialog() {
? ? CustomDialog.showBottomSheet(context, (ctx, dismiss) {
? ? ? return Container(
? ? ? ? height: 300,
? ? ? ? color: Colors.white,
? ? ? ? child: Center(child: TextButton(onPressed: () => dismiss(), child: const Text("POP")),),
? ? ? ? margin: const EdgeInsets.all(20),
? ? ? );
? ? });
? }
?
? void showDelayDialog() {
? ? CustomDialog.show(context, (context, dismiss) {
? ? ? //延時關(guān)閉
? ? ? Timer(const Duration(seconds: 2), () => dismiss());
?
? ? ? return Container(
? ? ? ? width: 200,
? ? ? ? height: 100,
? ? ? ? color: Colors.yellow,
? ? ? ? child: const Center(child: Text("等待"),),
? ? ? );
? ? }, cancellable: true);
? }
}

其中show方法中使用到的Dialog默認(rèn)使用material組件庫的,如果覺得有不合理的尺寸約束,可替換我修改過的Dialog組件,有其他需求也可在此定制,為什么不直接放棄使用此組件?主要涉及到其路由跳轉(zhuǎn)中的一些動畫布局之類的。

class Dialog extends StatelessWidget {
?
? const Dialog({
? ? Key? key,
? ? this.backgroundColor,
? ? this.elevation,
? ? this.insetAnimationDuration = const Duration(milliseconds: 100),
? ? this.insetAnimationCurve = Curves.decelerate,
? ? this.insetPadding = const EdgeInsets.symmetric(horizontal: 40.0, vertical: 24.0),
? ? this.clipBehavior = Clip.none,
? ? this.shape,
? ? this.alignment,
? ? this.child,
? }) : super(key: key);
?
?
? final Color? backgroundColor;
? final double? elevation;
? final Duration insetAnimationDuration;
? final Curve insetAnimationCurve;
? final EdgeInsets? insetPadding;
? final Clip clipBehavior;
? final ShapeBorder? shape;
? final AlignmentGeometry? alignment;
? final Widget? child;
?
? static const RoundedRectangleBorder _defaultDialogShape =
? RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0)));
? static const double _defaultElevation = 24.0;
?
? @override
? Widget build(BuildContext context) {
? ? final DialogTheme dialogTheme = DialogTheme.of(context);
? ? final EdgeInsets effectivePadding = MediaQuery.of(context).viewInsets + (insetPadding ?? EdgeInsets.zero);
? ? return AnimatedPadding(
? ? ? padding: effectivePadding,
? ? ? duration: insetAnimationDuration,
? ? ? curve: insetAnimationCurve,
? ? ? child: MediaQuery.removeViewInsets(
? ? ? ? removeLeft: true,
? ? ? ? removeTop: true,
? ? ? ? removeRight: true,
? ? ? ? removeBottom: true,
? ? ? ? context: context,
? ? ? ? child: Align(
? ? ? ? ? alignment: alignment ?? dialogTheme.alignment ?? Alignment.center,
? ? ? ? ? child: Material(
? ? ? ? ? ? color: backgroundColor ?? dialogTheme.backgroundColor ?? Theme.of(context).dialogBackgroundColor,
? ? ? ? ? ? elevation: elevation ?? dialogTheme.elevation ?? _defaultElevation,
? ? ? ? ? ? shape: shape ?? dialogTheme.shape ?? _defaultDialogShape,
? ? ? ? ? ? type: MaterialType.card,
? ? ? ? ? ? clipBehavior: clipBehavior,
? ? ? ? ? ? child: child,
? ? ? ? ? ),
? ? ? ? ),
? ? ? ),
? ? );
? }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 如何在Android App中集成支付寶和微信支付功能

    如何在Android App中集成支付寶和微信支付功能

    支付是各位Android開發(fā)者們在日常工作中經(jīng)常會遇到的一個需求,下面這篇文章主要給大家介紹了關(guān)于如何在Android App中集成支付寶和微信支付功能的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-05-05
  • Android Studio3.6.3 當(dāng)前最新版本數(shù)據(jù)庫查找與導(dǎo)出方法(圖文詳解)

    Android Studio3.6.3 當(dāng)前最新版本數(shù)據(jù)庫查找與導(dǎo)出方法(圖文詳解)

    這篇文章主要介紹了Android Studio3.6.3 當(dāng)前最新版本數(shù)據(jù)庫查找與導(dǎo)出方法,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-04-04
  • 使用Android造了個滾輪控件輪子示例

    使用Android造了個滾輪控件輪子示例

    這篇文章主要介紹了使用Android造了個滾輪控件輪子示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-02-02
  • Android實(shí)現(xiàn)象棋游戲

    Android實(shí)現(xiàn)象棋游戲

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)象棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • Android模糊處理簡單實(shí)現(xiàn)毛玻璃效果

    Android模糊處理簡單實(shí)現(xiàn)毛玻璃效果

    這篇文章主要介紹了Android模糊處理簡單實(shí)現(xiàn)毛玻璃效果的相關(guān)資料,需要的朋友可以參考下
    2016-02-02
  • Android圖片緩存之Lru算法(二)

    Android圖片緩存之Lru算法(二)

    LRU緩存簡單的說就是緩存一定量的數(shù)據(jù),當(dāng)超過設(shè)定的閾值時就把一些過期的數(shù)據(jù)刪除掉,這篇文章主要介紹了Android圖片緩存Lru算法,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android使用ScrollView實(shí)現(xiàn)滾動效果

    Android使用ScrollView實(shí)現(xiàn)滾動效果

    這篇文章主要為大家詳細(xì)介紹了Android使用ScrollView實(shí)現(xiàn)滾動效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-01-01
  • Android自定義圓角ImageView控件

    Android自定義圓角ImageView控件

    這篇文章主要為大家詳細(xì)介紹了Android自定義圓角ImageView的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • Android自定義布局實(shí)現(xiàn)仿qq側(cè)滑部分代碼

    Android自定義布局實(shí)現(xiàn)仿qq側(cè)滑部分代碼

    這篇文章主要為大家詳細(xì)介紹了自定義布局實(shí)現(xiàn)仿qq側(cè)滑Android部分代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Android Kotlin仿微信頭像裁剪圖片的方法示例

    Android Kotlin仿微信頭像裁剪圖片的方法示例

    這篇文章主要介紹了Android Kotlin仿微信頭像裁剪圖片的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08

最新評論