Flutter后台消息气泡显示插件background_bubbles的使用
Flutter后台消息气泡显示插件background_bubbles的使用
注意事项
以下代码片段演示了如何在Flutter应用中使用动画创建覆盖整个屏幕的背景气泡。
简单的方法
import 'package:background_bubbles/background_bubbles.dart';
BubblesAnimation(
backgroundColor: Colors.white,
particleColor: Colors.indigo,
particleCount: 500,
particleRadius: 5,
widget: Center(child: Text("Animated Bubbles")))
使用说明
要在Flutter应用中使用动画创建覆盖整个屏幕的背景气泡,下面是一个登录界面的设计示例供参考。
示例代码
import 'package:background_bubbles/background_bubbles.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// 此小部件是您的应用程序的根。
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter背景气泡',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({
super.key,
});
[@override](/user/override)
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
body: BubblesAnimation(
backgroundColor: Colors.white,
particleColor: Colors.indigo,
particleCount: 500,
particleRadius: 5,
widget: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20.0),
),
child: Padding(
padding: const EdgeInsets.only(
left: 15, right: 15, top: 5),
child: TextFormField(
decoration: const InputDecoration(
border: InputBorder.none,
labelText: '邮箱',
)))),
),
),
Center(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20.0),
),
child: Padding(
padding: const EdgeInsets.only(
left: 15, right: 15, top: 5),
child: TextFormField(
decoration: const InputDecoration(
border: InputBorder.none,
labelText: '密码',
)))),
),
),
Padding(
padding: const EdgeInsets.all(50),
child: SizedBox(
height: 50,
width: double.infinity,
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.amberAccent,
// padding:
// EdgeInsets.symmetric(horizontal: 50, vertical: 20),
textStyle: const TextStyle(
fontSize: 20, fontWeight: FontWeight.bold)),
child: const Text(
'登录',
style:
TextStyle(color: Colors.black, fontSize: 18.0),
),
),
)),
],
),
)));
}
}
更多关于Flutter后台消息气泡显示插件background_bubbles的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复