新增通知按鈕功能
This commit is contained in:
parent
8d9f204a44
commit
0030e025b8
@ -7,6 +7,76 @@ import 'reapair.dart';
|
|||||||
import 'activity.dart';
|
import 'activity.dart';
|
||||||
import 'announcement.dart';
|
import 'announcement.dart';
|
||||||
|
|
||||||
|
class NotificationIcon extends StatefulWidget {
|
||||||
|
const NotificationIcon({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<NotificationIcon> createState() => _NotificationIconState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _NotificationIconState extends State<NotificationIcon> {
|
||||||
|
List<String> _notifications = [];
|
||||||
|
int get _unreadCount => _notifications.length;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_fetchNotifications(); // 模擬 API 呼叫
|
||||||
|
}
|
||||||
|
|
||||||
|
void _fetchNotifications() async {
|
||||||
|
// 模擬從 API 取得資料
|
||||||
|
// await Future.delayed(const Duration(seconds: 1));
|
||||||
|
setState(() {
|
||||||
|
_notifications = ['4/15 管理費已出帳', '4/14 社區電梯保養通知', '4/13 新活動報名開始'];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Stack(
|
||||||
|
clipBehavior: Clip.none,
|
||||||
|
children: [
|
||||||
|
PopupMenuButton<String>(
|
||||||
|
icon: const Icon(Icons.notifications),
|
||||||
|
offset: const Offset(0, 40), // 👈 向下移開 40px,避免蓋住鈴鐺
|
||||||
|
onSelected: (value) {
|
||||||
|
ScaffoldMessenger.of(
|
||||||
|
context,
|
||||||
|
).showSnackBar(SnackBar(content: Text('點擊通知:$value')));
|
||||||
|
},
|
||||||
|
itemBuilder: (BuildContext context) {
|
||||||
|
return _notifications.map((String notification) {
|
||||||
|
return PopupMenuItem<String>(
|
||||||
|
value: notification,
|
||||||
|
child: Text(notification),
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
if (_unreadCount > 0)
|
||||||
|
Positioned(
|
||||||
|
right: 4,
|
||||||
|
top: 4,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(2),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.red,
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
constraints: const BoxConstraints(minWidth: 16, minHeight: 16),
|
||||||
|
child: Text(
|
||||||
|
'$_unreadCount',
|
||||||
|
style: const TextStyle(color: Colors.white, fontSize: 10),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class HomeContentPage extends StatelessWidget {
|
class HomeContentPage extends StatelessWidget {
|
||||||
const HomeContentPage({super.key});
|
const HomeContentPage({super.key});
|
||||||
|
|
||||||
@ -23,7 +93,8 @@ class HomeContentPage extends StatelessWidget {
|
|||||||
style: TextStyle(fontWeight: FontWeight.bold),
|
style: TextStyle(fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Stack(
|
NotificationIcon(),
|
||||||
|
/*Stack(
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.notifications),
|
icon: const Icon(Icons.notifications),
|
||||||
@ -52,7 +123,7 @@ class HomeContentPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),*/
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user