美文网首页
自定PopupRoute(一)

自定PopupRoute(一)

作者: neobuger | 来源:发表于2023-05-03 10:05 被阅读0次
    import 'package:flutter/material.dart';
    import 'dart:ui';
    
    
    class PopShow extends PopupRoute {
     final Duration _duration = Duration(milliseconds: 300);
    
    
     PopShow({Key ? key});
    
     static pop(BuildContext context) {
       // _CustomPopRouteViewState.of(context).dismiss();
       print("pop 了页面");
       Navigator.of(context).pop();
     }
    
     @override
     Color get barrierColor => Colors.transparent;
    
     @override
     bool get barrierDismissible => false;
    
     @override
     String get barrierLabel => "";
    
     @override
     Widget buildPage(BuildContext context, Animation<double> animation,
         Animation<double> secondaryAnimation) {
       return CustomPopRouteView();
     }
    
     @override
     Duration get transitionDuration => _duration;
    
    }
    
    class CustomPopRouteView extends StatefulWidget {
    
    
     CustomPopRouteView({Key? key}) : super(key: key);
    
     @override
     State<CustomPopRouteView> createState() => _CustomPopRouteViewState();
    }
    
    class _CustomPopRouteViewState extends State<CustomPopRouteView> {
     @override
     void initState() {
       print("开始创建");
    
       super.initState();
     }
    
     @override
     Widget build(BuildContext context) {
       return GestureDetector(
         onTap: (){
           Navigator.pop(context);
         },
         child: Container(
           // color: Colors.blue,
           child: Text("123"),
         ),
       );
     }
    }
    
    

    使用

     Navigator.push(context, PopShow());
    

    相关文章

      网友评论

          本文标题:自定PopupRoute(一)

          本文链接:https://www.haomeiwen.com/subject/ktazjdtx.html