2021-11-11 09:05:48 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2021-11-15 08:26:53 +00:00
|
|
|
// 提示信息, 组件右上角的小红点
|
2021-11-11 09:05:48 +00:00
|
|
|
class Badged extends StatelessWidget {
|
|
|
|
final String? badge;
|
|
|
|
final Widget child;
|
|
|
|
|
|
|
|
const Badged({Key? key, required this.child, this.badge}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (badge == null) {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
return Stack(
|
|
|
|
children: [
|
|
|
|
child,
|
2022-03-17 03:31:25 +00:00
|
|
|
Positioned(
|
2021-11-11 09:05:48 +00:00
|
|
|
right: 0,
|
2022-03-17 03:31:25 +00:00
|
|
|
child: Container(
|
|
|
|
padding: const EdgeInsets.all(1),
|
|
|
|
decoration: BoxDecoration(
|
2021-11-11 09:05:48 +00:00
|
|
|
color: Colors.red,
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
),
|
2022-03-17 03:31:25 +00:00
|
|
|
constraints: const BoxConstraints(
|
2021-11-11 09:05:48 +00:00
|
|
|
minWidth: 12,
|
|
|
|
minHeight: 12,
|
|
|
|
),
|
2022-03-17 03:31:25 +00:00
|
|
|
child: Text(
|
2021-11-11 09:05:48 +00:00
|
|
|
badge!,
|
2022-03-17 03:31:25 +00:00
|
|
|
style: const TextStyle(
|
2021-11-11 09:05:48 +00:00
|
|
|
color: Colors.white,
|
|
|
|
fontSize: 8,
|
|
|
|
),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|