历史记录
This commit is contained in:
@@ -1,15 +1,17 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class AnimateText extends StatefulWidget {
|
import 'models/merit_record.dart';
|
||||||
final String text;
|
|
||||||
|
|
||||||
const AnimateText({Key? key, required this.text}) : super(key: key);
|
class AnimateText extends StatefulWidget {
|
||||||
|
final MeritRecord record;
|
||||||
|
|
||||||
|
const AnimateText({Key? key, required this.record}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AnimateText> createState() => _FadTextState();
|
State<AnimateText> createState() => _AnimateTextState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FadTextState extends State<AnimateText> with SingleTickerProviderStateMixin {
|
class _AnimateTextState extends State<AnimateText> with SingleTickerProviderStateMixin {
|
||||||
late AnimationController controller;
|
late AnimationController controller;
|
||||||
late Animation<double> opacity;
|
late Animation<double> opacity;
|
||||||
late Animation<Offset> position;
|
late Animation<Offset> position;
|
||||||
@@ -18,17 +20,23 @@ class _FadTextState extends State<AnimateText> with SingleTickerProviderStateMix
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
controller = AnimationController(vsync: this, duration: Duration(milliseconds: 500));
|
controller =
|
||||||
|
AnimationController(vsync: this, duration: Duration(milliseconds: 500));
|
||||||
opacity = Tween(begin: 1.0, end: 0.0).animate(controller);
|
opacity = Tween(begin: 1.0, end: 0.0).animate(controller);
|
||||||
scale = Tween(begin: 1.0, end: 0.9).animate(controller);
|
scale = Tween(begin: 1.0, end: 0.9).animate(controller);
|
||||||
position = Tween<Offset>(begin: const Offset(0, 2), end: Offset.zero,).animate(controller);
|
position = Tween<Offset>(
|
||||||
|
begin: const Offset(0, 2),
|
||||||
|
end: Offset.zero,
|
||||||
|
).animate(controller);
|
||||||
controller.forward();
|
controller.forward();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didUpdateWidget(covariant AnimateText oldWidget) {
|
void didUpdateWidget(covariant AnimateText oldWidget) {
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
controller.forward(from: 0);
|
if (oldWidget.record.id != widget.record.id) {
|
||||||
|
controller.forward(from: 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -45,8 +53,8 @@ class _FadTextState extends State<AnimateText> with SingleTickerProviderStateMix
|
|||||||
position: position,
|
position: position,
|
||||||
child: FadeTransition(
|
child: FadeTransition(
|
||||||
opacity: opacity,
|
opacity: opacity,
|
||||||
child: Text(widget.text),
|
child: Text('功德+${widget.record.value}'),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
lib/muyu/models/merit_record.dart
Normal file
9
lib/muyu/models/merit_record.dart
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class MeritRecord {
|
||||||
|
final String id;
|
||||||
|
final int timestamp;
|
||||||
|
final int value;
|
||||||
|
final String image;
|
||||||
|
final String audio;
|
||||||
|
|
||||||
|
MeritRecord(this.id, this.timestamp, this.value, this.image, this.audio);
|
||||||
|
}
|
||||||
@@ -5,13 +5,16 @@ import 'package:flutter/cupertino.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_first_station/muyu/animate_text.dart';
|
import 'package:flutter_first_station/muyu/animate_text.dart';
|
||||||
import 'package:flutter_first_station/muyu/options/select_audio.dart';
|
import 'package:flutter_first_station/muyu/options/select_audio.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
import 'models/audio_option.dart';
|
import 'models/audio_option.dart';
|
||||||
import 'models/image_option.dart';
|
import 'models/image_option.dart';
|
||||||
|
import 'models/merit_record.dart';
|
||||||
import 'muyu_image.dart';
|
import 'muyu_image.dart';
|
||||||
|
|
||||||
import 'count_panel.dart';
|
import 'count_panel.dart';
|
||||||
import 'muyu_app_bar.dart';
|
import 'muyu_app_bar.dart';
|
||||||
import 'options/select_image.dart';
|
import 'options/select_image.dart';
|
||||||
|
import 'record_history.dart';
|
||||||
|
|
||||||
class MuyuPage extends StatefulWidget {
|
class MuyuPage extends StatefulWidget {
|
||||||
const MuyuPage({Key? key}) : super(key: key);
|
const MuyuPage({Key? key}) : super(key: key);
|
||||||
@@ -22,12 +25,16 @@ class MuyuPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _MuyuPageState extends State<MuyuPage> {
|
class _MuyuPageState extends State<MuyuPage> {
|
||||||
int _counter = 0;
|
int _counter = 0;
|
||||||
int _cruValue = 0;
|
MeritRecord? _cruRecord;
|
||||||
|
|
||||||
int _activeImageIndex = 0;
|
int _activeImageIndex = 0;
|
||||||
int _activeAudioIndex = 0;
|
int _activeAudioIndex = 0;
|
||||||
|
|
||||||
final Random _random = Random();
|
final Random _random = Random();
|
||||||
|
final Uuid uuid = Uuid();
|
||||||
|
|
||||||
|
List<MeritRecord> _records = [];
|
||||||
|
|
||||||
|
|
||||||
final List<AudioOption> audioOptions = const [
|
final List<AudioOption> audioOptions = const [
|
||||||
AudioOption('音效1', 'muyu_1.mp3'),
|
AudioOption('音效1', 'muyu_1.mp3'),
|
||||||
@@ -78,7 +85,7 @@ class _MuyuPageState extends State<MuyuPage> {
|
|||||||
image: activeImage,
|
image: activeImage,
|
||||||
onTap: _onKnock,
|
onTap: _onKnock,
|
||||||
),
|
),
|
||||||
if (_cruValue != 0) AnimateText(text: '功德+$_cruValue')
|
if (_cruRecord != null) AnimateText(record: _cruRecord!,)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -87,7 +94,9 @@ class _MuyuPageState extends State<MuyuPage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _toHistory() {}
|
void _toHistory() {
|
||||||
|
Navigator.of(context).push(MaterialPageRoute(builder: (_)=>RecordHistory(record: _records.reversed.toList())));
|
||||||
|
}
|
||||||
|
|
||||||
void _onTapSwitchAudio() {
|
void _onTapSwitchAudio() {
|
||||||
showCupertinoModalPopup(
|
showCupertinoModalPopup(
|
||||||
@@ -118,8 +127,17 @@ class _MuyuPageState extends State<MuyuPage> {
|
|||||||
void _onKnock() {
|
void _onKnock() {
|
||||||
pool?.start();
|
pool?.start();
|
||||||
setState(() {
|
setState(() {
|
||||||
_cruValue = knockValue;
|
String id = uuid.v4();
|
||||||
_counter += _cruValue;
|
_cruRecord = MeritRecord(
|
||||||
|
id,
|
||||||
|
DateTime.now().millisecondsSinceEpoch,
|
||||||
|
knockValue,
|
||||||
|
activeImage,
|
||||||
|
audioOptions[_activeAudioIndex].name,
|
||||||
|
);
|
||||||
|
_counter += _cruRecord!.value;
|
||||||
|
// 添加功德记录
|
||||||
|
_records.add(_cruRecord!);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
40
lib/muyu/record_history.dart
Normal file
40
lib/muyu/record_history.dart
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
@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,),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget? _buildItem(BuildContext context, int index) {
|
||||||
|
MeritRecord merit = record[index];
|
||||||
|
String date = format.format(DateTime.fromMillisecondsSinceEpoch(merit.timestamp));
|
||||||
|
return ListTile(
|
||||||
|
leading: CircleAvatar(
|
||||||
|
backgroundColor: Colors.blue,
|
||||||
|
backgroundImage: AssetImage(merit.image),
|
||||||
|
),
|
||||||
|
title: Text('功德 +${merit.value}'),
|
||||||
|
subtitle: Text('${merit.audio}'),
|
||||||
|
trailing: Text(date,style: const TextStyle(fontSize: 12,color: Colors.grey),),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
10
pubspec.lock
10
pubspec.lock
@@ -192,6 +192,14 @@ packages:
|
|||||||
url: "https://pub.flutter-io.cn"
|
url: "https://pub.flutter-io.cn"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.2"
|
version: "4.0.2"
|
||||||
|
intl:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: intl
|
||||||
|
sha256: "3bc132a9dbce73a7e4a21a17d06e1878839ffbf975568bc875c60537824b0c4d"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "0.18.1"
|
||||||
js:
|
js:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -390,7 +398,7 @@ packages:
|
|||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.1"
|
version: "1.3.1"
|
||||||
uuid:
|
uuid:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: uuid
|
name: uuid
|
||||||
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
|
sha256: "648e103079f7c64a36dc7d39369cabb358d377078a051d6ae2ad3aa539519313"
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ dependencies:
|
|||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
flame_audio: ^2.0.2
|
flame_audio: ^2.0.2
|
||||||
|
uuid: ^3.0.7
|
||||||
|
intl: ^0.18.1
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
# Use with the CupertinoIcons class for iOS style icons.
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.2
|
||||||
|
|||||||
Reference in New Issue
Block a user