import 'package:flutter/material.dart'; import 'package:flutter_common/widget/common_widget.dart'; import 'package:intl/intl.dart'; class Welcome extends StatefulWidget { const Welcome({super.key}); @override State createState() => _WelcomeState(); } class _WelcomeState extends State { @override void initState() { super.initState(); } String _formatCurrentDate() { final now = DateTime.now(); return "${DateFormat('yyyy年MM月dd日').format(now)} ${_getWeekday(now.weekday)}"; } // 数字星期转中文 String _getWeekday(int weekday) { const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']; return weekdays[weekday - 1]; } String getGreeting() { int hour = DateTime.now().hour; if (hour >= 5 && hour < 12) { return '早上好'; } else if (hour >= 12 && hour < 18) { return '下午好'; } else { return '晚上好'; } } @override Widget build(BuildContext context) { return CommonCard( child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( getGreeting(), style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), const SizedBox(height: 4), Text( '今天是 ${_formatCurrentDate()}', style: const TextStyle(fontSize: 12, color: Colors.grey), ), ], ) ], ), ); } }