This commit is contained in:
Dmitry 2024-09-02 22:47:37 +03:00
parent a348a0ac65
commit d73f6c2427
5 changed files with 70 additions and 45 deletions

View file

@ -2,7 +2,8 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:mnemo_cards/features/tests/test_manager.dart'; import 'package:mnemo_cards/features/tests/test_manager.dart';
import 'package:mnemo_cards/features/tests/test_widgets/common_test_question_widget.dart'; import 'package:mnemo_cards/features/tests/test_widgets/common_test_question_widget.dart';
import 'package:mnemo_cards_common/mnemo_cards_common.dart'; import 'package:mnemo_cards_common/mnemo_cards_common.dart'
hide NullableIterableHelper;
import '../../../di/locator.dart'; import '../../../di/locator.dart';
import '../question_states/input_buttons_test_state.dart'; import '../question_states/input_buttons_test_state.dart';
import 'test_button.dart'; import 'test_button.dart';
@ -82,7 +83,10 @@ class InputButtonsTestWidget extends StatelessWidget {
} }
int splitIndex = 0; int splitIndex = 0;
if (model.template.length * 32 > constraints.maxWidth * 0.9) { if (model.template.characters.where((c) => c == '_').length * 32 +
model.template.characters.where((c) => c != '_').length *
18 >
constraints.maxWidth * 0.9) {
splitIndex = model.template.indexOf( splitIndex = model.template.indexOf(
' ', ' ',
(model.template.length / 2).ceil(), (model.template.length / 2).ceil(),
@ -104,34 +108,36 @@ class InputButtonsTestWidget extends StatelessWidget {
splitIndex = 0; splitIndex = 0;
} }
final stringRows = [
if (splitIndex > 0) model.template.substring(0, splitIndex),
model.template.substring(splitIndex),
];
int stateAnswerIndex = 0; int stateAnswerIndex = 0;
final letters = model.template final letters =
.split('') stringRows.map((row) => row.split(RegExp('(?=_)|(?<=_)')).map(
.map( (letter) => letter == '_'
(letter) => letter == '_' ? _Letter(
? _Letter( text: state.answer.length > stateAnswerIndex
text: state.answer.length > stateAnswerIndex ? state.answer[stateAnswerIndex++]
? state.answer[stateAnswerIndex++] : ' ',
: ' ', borderColor: testColor,
borderColor: testColor, )
) : _Letter.readOnly(
: _Letter.readOnly( text: letter,
text: letter, ),
), ));
)
.toList();
final rows = [ final rows = [
if (splitIndex > 0) if (splitIndex > 0)
Padding( Padding(
padding: const EdgeInsets.only(bottom: 8.0), padding: const EdgeInsets.only(bottom: 8.0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: letters.sublist(0, splitIndex), children: letters.first.toList(),
), ),
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: letters.sublist(splitIndex), children: letters.last.toList(),
) )
]; ];
@ -216,25 +222,32 @@ class _Letter extends StatelessWidget {
final String text; final String text;
final Color? borderColor; final Color? borderColor;
final Color? backgroundColor; final Color? backgroundColor;
final double _width; final double? _width;
final double _padding; final double _padding;
final double _margin; final double _innerPadding;
final double _innerMargin;
_Letter({ _Letter({
this.text = '', this.text = '',
this.borderColor, this.borderColor,
this.backgroundColor, this.backgroundColor,
}) : this._width = 32, }) : this._width = 32,
this._padding = 5, this._padding = 0,
this._margin = 2.0; this._innerPadding = 5,
this._innerMargin = 2.0;
_Letter.readOnly({ _Letter.readOnly({
this.text = '', this.text = '',
}) : this.borderColor = null, }) : this.borderColor = null,
this.backgroundColor = Colors.transparent, this.backgroundColor = Colors.transparent,
this._width = text == ' ' ? 10 : 20, this._width = text == ' '
this._padding = 0.0, ? 10
this._margin = 0.0; : text.length == 1
? 20
: null,
this._padding = 5.0,
this._innerPadding = 0.0,
this._innerMargin = 0.0;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -242,8 +255,9 @@ class _Letter extends StatelessWidget {
width: _width, width: _width,
height: 45, height: 45,
alignment: Alignment.center, alignment: Alignment.center,
margin: EdgeInsets.all(_margin), margin: EdgeInsets.all(_innerMargin),
padding: EdgeInsets.all(_padding), padding: EdgeInsets.all(_innerPadding)
.copyWith(right: _padding + _innerPadding),
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
decoration: BoxDecoration( decoration: BoxDecoration(
color: backgroundColor ?? Theme.of(context).scaffoldBackgroundColor, color: backgroundColor ?? Theme.of(context).scaffoldBackgroundColor,
@ -254,7 +268,9 @@ class _Letter extends StatelessWidget {
color: backgroundColor ?? Theme.of(context).scaffoldBackgroundColor, color: backgroundColor ?? Theme.of(context).scaffoldBackgroundColor,
child: Text( child: Text(
text, text,
style: Theme.of(context).textTheme.titleLarge, style: Theme.of(context).textTheme.titleLarge?.copyWith(
letterSpacing: 1.1,
),
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
), ),

View file

@ -37,8 +37,9 @@ final appRouter = AppRouter(ADMIN_BUILD);
AndroidDeviceInfo? androidDeviceInfo; AndroidDeviceInfo? androidDeviceInfo;
Future<bool> _screenOff() async => Future<bool> _screenOff() async => ADMIN_BUILD
ADMIN_BUILD || await NoScreenshot.instance.screenshotOff(); ? await NoScreenshot.instance.screenshotOn()
: await NoScreenshot.instance.screenshotOff();
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
@ -83,17 +84,29 @@ void main() async {
unawaited(initFirebase()); unawaited(initFirebase());
print('initing... ${stopwatch.elapsedMilliseconds}'); print('initing... ${stopwatch.elapsedMilliseconds}');
await Future.wait([ await Future.wait([
locator.packCacheManager.init().then((_) => print('packCacheManager inited')), locator.packCacheManager
locator.previewPackHolder.init().then((_) => print('previewPackHolder inited')), .init()
locator.previewPackPoller.init().then((_) => print('previewPackPoller inited')), .then((_) => print('packCacheManager inited')),
locator.previewPackHolder
.init()
.then((_) => print('previewPackHolder inited')),
locator.previewPackPoller
.init()
.then((_) => print('previewPackPoller inited')),
locator.packManager.init().then((_) => print('packManager inited')), locator.packManager.init().then((_) => print('packManager inited')),
locator.userManager.init().then((_) => print('userManager inited')), locator.userManager.init().then((_) => print('userManager inited')),
locator.favoriteCardsController.init().then((_) => print('favoriteCardsController inited')), locator.favoriteCardsController
locator.previewPackPoller.init().then((_) => print('previewPackPoller inited')), .init()
locator.deeplinkManager.init().then((_) => print('deeplinkManager inited')), .then((_) => print('favoriteCardsController inited')),
locator.previewPackPoller
.init()
.then((_) => print('previewPackPoller inited')),
locator.deeplinkManager
.init()
.then((_) => print('deeplinkManager inited')),
]); ]);
await locator.packUpdater.init().then((_) => print('packUpdater inited')); await locator.packUpdater.init().then((_) => print('packUpdater inited'));
print('initing complete ${stopwatch.elapsedMilliseconds}'); print('initing complete ${stopwatch.elapsedMilliseconds}');
if (!kIsWeb) unawaited(MobileAds.initialize()); if (!kIsWeb) unawaited(MobileAds.initialize());
print('mobile ads ${stopwatch.elapsedMilliseconds}'); print('mobile ads ${stopwatch.elapsedMilliseconds}');
print('runApp ${stopwatch.elapsedMilliseconds}'); print('runApp ${stopwatch.elapsedMilliseconds}');
@ -117,7 +130,7 @@ Future<void> _fillSp() async {
} }
final soundSpeed = globalSharedPreferences.getDouble('sound_speed'); final soundSpeed = globalSharedPreferences.getDouble('sound_speed');
if (soundSpeed == null) { if (soundSpeed == null) {
await globalSharedPreferences.setDouble('sound_speed', 1.0); await globalSharedPreferences.setDouble('sound_speed', 0.8);
} }
final autoPlay = globalSharedPreferences.getBool('auto_play_sound_tests'); final autoPlay = globalSharedPreferences.getBool('auto_play_sound_tests');
if (autoPlay == null) { if (autoPlay == null) {

View file

@ -23,7 +23,7 @@ class AudioPlayer {
var speed = globalSharedPreferences.getDouble('sound_speed'); var speed = globalSharedPreferences.getDouble('sound_speed');
if (speed == null) { if (speed == null) {
speed = 0.8; speed = 0.8;
globalSharedPreferences.setDouble('sound_speed', 0.8); globalSharedPreferences.setDouble('sound_speed', speed);
} }
await flutterTts.setSpeechRate(speed); await flutterTts.setSpeechRate(speed);
flutterTts.speak(playText); flutterTts.speak(playText);

View file

@ -7,9 +7,5 @@ mixin Api {
!ADMIN_BUILD || (globalSharedPreferences.getBool('env') ?? true) !ADMIN_BUILD || (globalSharedPreferences.getBool('env') ?? true)
//prod //prod
? 'https://89.19.210.178:8080' //FirebaseRepository.appConfig.path ? 'https://89.19.210.178:8080' //FirebaseRepository.appConfig.path
: androidDeviceInfo!.isPhysicalDevice : 'https://192.168.31.158:8080';
//device to localhost
? 'https://192.168.31.158:8080'
: //emulator to localhost
'https://10.0.2.2:8080';
} }