木鱼配置存储
This commit is contained in:
@@ -6,6 +6,7 @@ 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 'package:uuid/uuid.dart';
|
||||||
|
import '../storage/sp_storage.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 'models/merit_record.dart';
|
||||||
@@ -23,7 +24,8 @@ class MuyuPage extends StatefulWidget {
|
|||||||
State<MuyuPage> createState() => _MuyuPageState();
|
State<MuyuPage> createState() => _MuyuPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MuyuPageState extends State<MuyuPage> with AutomaticKeepAliveClientMixin {
|
class _MuyuPageState extends State<MuyuPage>
|
||||||
|
with AutomaticKeepAliveClientMixin {
|
||||||
int _counter = 0;
|
int _counter = 0;
|
||||||
MeritRecord? _cruRecord;
|
MeritRecord? _cruRecord;
|
||||||
|
|
||||||
@@ -52,11 +54,22 @@ class _MuyuPageState extends State<MuyuPage> with AutomaticKeepAliveClientMixin
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_initAudioPool();
|
_initAudioPool();
|
||||||
|
_initConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _initConfig() async{
|
||||||
|
Map<String,dynamic> config = await SpStorage.instance.readMuYUConfig();
|
||||||
|
_counter = config['counter']??0;
|
||||||
|
_activeImageIndex = config['activeImageIndex']??0;
|
||||||
|
_activeAudioIndex = config['activeAudioIndex']??0;
|
||||||
|
setState(() {
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _initAudioPool() async {
|
void _initAudioPool() async {
|
||||||
pool = await FlameAudio.createPool(
|
pool = await FlameAudio.createPool(
|
||||||
'muyu_1.mp3',
|
audioOptions[_activeAudioIndex].src,
|
||||||
maxPlayers: 1,
|
maxPlayers: 1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -84,8 +97,7 @@ class _MuyuPageState extends State<MuyuPage> with AutomaticKeepAliveClientMixin
|
|||||||
image: activeImage,
|
image: activeImage,
|
||||||
onTap: _onKnock,
|
onTap: _onKnock,
|
||||||
),
|
),
|
||||||
if (_cruRecord != null)
|
if (_cruRecord != null) AnimateText(record: _cruRecord!)
|
||||||
AnimateText(record: _cruRecord!)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -142,11 +154,20 @@ class _MuyuPageState extends State<MuyuPage> with AutomaticKeepAliveClientMixin
|
|||||||
audioOptions[_activeAudioIndex].name,
|
audioOptions[_activeAudioIndex].name,
|
||||||
);
|
);
|
||||||
_counter += _cruRecord!.value;
|
_counter += _cruRecord!.value;
|
||||||
|
saveConfig();
|
||||||
// 添加功德记录
|
// 添加功德记录
|
||||||
_records.add(_cruRecord!);
|
_records.add(_cruRecord!);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void saveConfig() {
|
||||||
|
SpStorage.instance.saveMuYUConfig(
|
||||||
|
counter: _counter,
|
||||||
|
activeImageIndex: _activeImageIndex,
|
||||||
|
activeAudioIndex: _activeAudioIndex,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
String get activeImage => imageOptions[_activeImageIndex].src;
|
String get activeImage => imageOptions[_activeImageIndex].src;
|
||||||
|
|
||||||
int get knockValue {
|
int get knockValue {
|
||||||
@@ -160,6 +181,7 @@ class _MuyuPageState extends State<MuyuPage> with AutomaticKeepAliveClientMixin
|
|||||||
if (value == _activeImageIndex) return;
|
if (value == _activeImageIndex) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_activeImageIndex = value;
|
_activeImageIndex = value;
|
||||||
|
saveConfig();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,6 +191,7 @@ class _MuyuPageState extends State<MuyuPage> with AutomaticKeepAliveClientMixin
|
|||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
if (value == _activeAudioIndex) return;
|
if (value == _activeAudioIndex) return;
|
||||||
_activeAudioIndex = value;
|
_activeAudioIndex = value;
|
||||||
|
saveConfig();
|
||||||
pool = await FlameAudio.createPool(
|
pool = await FlameAudio.createPool(
|
||||||
activeAudio,
|
activeAudio,
|
||||||
maxPlayers: 1,
|
maxPlayers: 1,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'dart:convert';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
const String kGuessSpKey = 'guess-config';
|
const String kGuessSpKey = 'guess-config';
|
||||||
|
const String kMuYUSpKey = 'muyu-config';
|
||||||
|
|
||||||
class SpStorage {
|
class SpStorage {
|
||||||
SpStorage._();
|
SpStorage._();
|
||||||
@@ -22,18 +23,37 @@ class SpStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> saveGuessConfig({
|
Future<bool> saveGuessConfig({
|
||||||
bool? guessing,
|
required bool guessing,
|
||||||
int? value,
|
required int value,
|
||||||
}) async {
|
}) async {
|
||||||
await initSpWhenNull();
|
await initSpWhenNull();
|
||||||
String content = json.encode({'guessing': guessing, 'value': value});
|
String content = json.encode({'guessing': guessing, 'value': value});
|
||||||
return _sp!.setString(kGuessSpKey, content);
|
return _sp!.setString(kGuessSpKey, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String,dynamic>> readGuessConfig() async {
|
Future<Map<String, dynamic>> readGuessConfig() async {
|
||||||
await initSpWhenNull();
|
await initSpWhenNull();
|
||||||
String content = _sp!.getString(kGuessSpKey)??"{}";
|
String content = _sp!.getString(kGuessSpKey) ?? "{}";
|
||||||
return json.decode(content);
|
return json.decode(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> saveMuYUConfig({
|
||||||
|
required int counter,
|
||||||
|
required int activeImageIndex,
|
||||||
|
required int activeAudioIndex,
|
||||||
|
}) async {
|
||||||
|
await initSpWhenNull();
|
||||||
|
String content = json.encode({
|
||||||
|
'counter': counter,
|
||||||
|
'activeImageIndex': activeImageIndex,
|
||||||
|
'activeAudioIndex': activeAudioIndex,
|
||||||
|
});
|
||||||
|
return _sp!.setString(kMuYUSpKey, content);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, dynamic>> readMuYUConfig() async {
|
||||||
|
await initSpWhenNull();
|
||||||
|
String content = _sp!.getString(kMuYUSpKey) ?? "{}";
|
||||||
|
return json.decode(content);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user