历史记录

This commit is contained in:
toly
2023-05-04 07:04:56 +08:00
parent b75bf0227f
commit 82cf031835
2 changed files with 35 additions and 19 deletions

View File

@@ -35,7 +35,6 @@ class _MuyuPageState extends State<MuyuPage> {
List<MeritRecord> _records = [];
final List<AudioOption> audioOptions = const [
AudioOption('音效1', 'muyu_1.mp3'),
AudioOption('音效2', 'muyu_2.mp3'),
@@ -85,7 +84,8 @@ class _MuyuPageState extends State<MuyuPage> {
image: activeImage,
onTap: _onKnock,
),
if (_cruRecord != null) AnimateText(record: _cruRecord!,)
if (_cruRecord != null)
AnimateText(record: _cruRecord!)
],
),
),
@@ -95,7 +95,13 @@ class _MuyuPageState extends State<MuyuPage> {
}
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<MuyuPage> {
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;

View File

@@ -6,26 +6,35 @@ import 'models/merit_record.dart';
DateFormat format = DateFormat('yyyy年MM月dd日 HH:mm:ss');
class RecordHistory extends StatelessWidget {
final List<MeritRecord> record;
const RecordHistory({Key? key, required this.record}) : super(key: key);
final List<MeritRecord> 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),),
);
}
}