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

View file

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

View file

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

View file

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