栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

从屏幕顶部抖动通知

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

从屏幕顶部抖动通知

Flutter使您可以借助Overlay类创建通知。 要使这些动画从顶部进入屏幕,可以将SlideTransition 与AnimationController 结合使用。 这是我创建的示例应用程序:

import 'package:flutter/material.dart';void main() => runApp(MyApp());class MyApp extends StatelessWidget {  @override  Widget build(BuildContext context) {    return MaterialApp(home: Home());  }}class Home extends StatelessWidget {  @override  Widget build(BuildContext context) {    return Scaffold(      body: Center(        child: RaisedButton.icon(          icon: Icon(Icons.notifications_active),          label: Text('Notify!'),          onPressed: () { Navigator.of(context)     .overlay     .insert(OverlayEntry(builder: (BuildContext context) {   return FunkyNotification(); }));          },        ),      ),    );  }}class FunkyNotification extends StatefulWidget {  @override  State<StatefulWidget> createState() => FunkyNotificationState();}class FunkyNotificationState extends State<FunkyNotification>    with SingleTickerProviderStateMixin {  AnimationController controller;  Animation<Offset> position;  @override  void initState() {    super.initState();    controller =        AnimationController(vsync: this, duration: Duration(milliseconds: 750));    position = Tween<Offset>(begin: Offset(0.0, -4.0), end: Offset.zero)        .animate( CurvedAnimation(parent: controller, curve: Curves.bounceInOut));    controller.forward();  }  @override  Widget build(BuildContext context) {    return SafeArea(      child: Material(        color: Colors.transparent,        child: Align(          alignment: Alignment.topCenter,          child: Padding( padding: EdgeInsets.only(top: 32.0), child: SlideTransition(   position: position,   child: Container(     decoration: ShapeDecoration(         color: Colors.deepPurple,         shape: RoundedRectangleBorder(  borderRadius: BorderRadius.circular(16.0))),     child: Padding(       padding: EdgeInsets.all(10.0),       child: Text(         'Notification!',         style: TextStyle(  color: Colors.white, fontWeight: FontWeight.bold),       ),     ),   ), ),          ),        ),      ),    );  }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/398200.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号