diff --git a/lib/muyu/muyu_page.dart b/lib/muyu/muyu_page.dart index 70dee04..1e2b9b7 100644 --- a/lib/muyu/muyu_page.dart +++ b/lib/muyu/muyu_page.dart @@ -35,7 +35,6 @@ class _MuyuPageState extends State { List _records = []; - final List audioOptions = const [ AudioOption('音效1', 'muyu_1.mp3'), AudioOption('音效2', 'muyu_2.mp3'), @@ -85,7 +84,8 @@ class _MuyuPageState extends State { image: activeImage, onTap: _onKnock, ), - if (_cruRecord != null) AnimateText(record: _cruRecord!,) + if (_cruRecord != null) + AnimateText(record: _cruRecord!) ], ), ), @@ -95,7 +95,13 @@ class _MuyuPageState extends State { } void _toHistory() { - Navigator.of(context).push(MaterialPageRoute(builder: (_)=>RecordHistory(record: _records.reversed.toList()))); + Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => RecordHistory( + records: _records.reversed.toList(), + ), + ), + ); } void _onTapSwitchAudio() { @@ -159,7 +165,7 @@ class _MuyuPageState extends State { String get activeAudio => audioOptions[_activeAudioIndex].src; - void _onSelectAudio(int value) async{ + void _onSelectAudio(int value) async { Navigator.of(context).pop(); if (value == _activeAudioIndex) return; _activeAudioIndex = value; diff --git a/lib/muyu/record_history.dart b/lib/muyu/record_history.dart index c223e5e..effd4f9 100644 --- a/lib/muyu/record_history.dart +++ b/lib/muyu/record_history.dart @@ -6,26 +6,35 @@ import 'models/merit_record.dart'; DateFormat format = DateFormat('yyyy年MM月dd日 HH:mm:ss'); class RecordHistory extends StatelessWidget { - final List record; - const RecordHistory({Key? key, required this.record}) : super(key: key); + final List records; + + const RecordHistory({Key? key, required this.records}) : super(key: key); @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - iconTheme: const IconThemeData(color: Colors.black), - centerTitle: true, - title: const Text('功德记录',style: TextStyle(color: Colors.black,fontSize: 16),), - elevation: 0, - backgroundColor: Colors.white,), - body: ListView.builder( - itemBuilder: _buildItem,itemCount: record.length,), + appBar:_buildAppBar(), + body: Column( + children: List.generate(records.length, (index)=>_buildItem(context,index)), + ), + // body: ListView.builder( + // itemBuilder: _buildItem, itemCount: records.length, + // ), ); } - Widget? _buildItem(BuildContext context, int index) { - MeritRecord merit = record[index]; + PreferredSizeWidget _buildAppBar() => + AppBar( + iconTheme: const IconThemeData(color: Colors.black), + centerTitle: true, + title: const Text( + '功德记录', style: TextStyle(color: Colors.black, fontSize: 16),), + elevation: 0, + backgroundColor: Colors.white, + ); + + Widget _buildItem(BuildContext context, int index) { + MeritRecord merit = records[index]; String date = format.format(DateTime.fromMillisecondsSinceEpoch(merit.timestamp)); return ListTile( leading: CircleAvatar( @@ -33,8 +42,9 @@ class RecordHistory extends StatelessWidget { backgroundImage: AssetImage(merit.image), ), title: Text('功德 +${merit.value}'), - subtitle: Text('${merit.audio}'), - trailing: Text(date,style: const TextStyle(fontSize: 12,color: Colors.grey),), + subtitle: Text(merit.audio), + trailing: Text( + date, style: const TextStyle(fontSize: 12, color: Colors.grey),), ); } }