Skip to content

Commit

Permalink
fix: some fixes from feedback (#30)
Browse files Browse the repository at this point in the history
* fix: additional line in contacts

* fix: quick button styling

* feat: disable system font size scaling

* feat: long tile shadows adjustments

* feat: game adjustments

* fixed: jumping bottom nav bar

* fixed anim controller dispose error

* request textfield focus after win

* feat: fake anim loading only from button action

* addressed flutter/flutter#113895

* fix another possible leak

* fix: more leak checks, focus text input also if wrong answer from textfield action

* one more mounted check in nepanikar_button.dart
  • Loading branch information
mzdm authored Oct 23, 2022
1 parent 6b5ef3f commit bb3e0bf
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 93 deletions.
2 changes: 1 addition & 1 deletion assets/contacts/all_contacts.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"countryContacts":[{"languageTag":"cs","phoneContacts":[{"pinned":true,"title":"Linka bezpečí","tel":"116 111","subtitle":"Nonstop zdarma","runtimeType":"default"},{"pinned":true,"title":"Linka psychické pomoci","tel":"116 123","subtitle":"Nonstop zdarma","runtimeType":"default"},{"title":"Modrá linka","subtitle":"Nonstop","subPhoneContacts":[{"title":"Mobil","tel":"731 197 477","action":"phone"},{"title":"Mobil","tel":"608 902 410","action":"phone"}],"runtimeType":"subList"},{"pinned":false,"title":"Linka pro rodinu a školu","tel":"116 000","subtitle":"Nonstop zdarma","runtimeType":"default"},{"pinned":false,"title":"Pražská linka důvěry","tel":"222 580 697","subtitle":"Nonstop","runtimeType":"default"},{"pinned":false,"title":"Linka důvěry CKI Bohnice","tel":"284 016 666","subtitle":"Nonstop","runtimeType":"default"},{"title":"Linka důvěry Dětského krizového centra","subtitle":"Nonstop","subPhoneContacts":[{"title":"Telefon","tel":"241 484 149","action":"phone"},{"title":"Mobil","tel":"777 715 215","action":"phone"}],"runtimeType":"subList"},{"pinned":false,"title":"Linka Anabell (poruchy přijmu potravy)","tel":"774 467 293","subtitle":"Pondělí\t8–16 hodin\nÚterý\t10–18 hodin\nStředa–pátek\t8–16 hodin\n","runtimeType":"default"}],"crisisCenterContacts":[{"title":"CrisisCenterContact TODO"}],"chatContacts":[{"title":"Poradna 1 - TODO","subtitle":null},{"title":"Poradna 2 - TODO","subtitle":null}],"universityContacts":[{"title":"Uni Contacts TODO"}]},{"languageTag":"en","phoneContacts":[{"pinned":true,"title":"TODO number 1","tel":"116 111","subtitle":"Nonstop","runtimeType":"default"},{"pinned":false,"title":"Example 2","tel":"123 456","subtitle":null,"runtimeType":"default"}],"crisisCenterContacts":null,"chatContacts":null,"universityContacts":null},{"languageTag":"sk","phoneContacts":[{"pinned":true,"title":"Linka detskej istoty","tel":"116 123","subtitle":"Nonstop zdarma","runtimeType":"default"},{"pinned":false,"title":"Krízová linka pomoci","tel":"0800 500 333","subtitle":"Nonstop zdarma","runtimeType":"default"},{"pinned":false,"title":"Liga za duševné zdravie Slovensko","tel":"0800 800 566","subtitle":"Nonstop zdarma","runtimeType":"default"}],"crisisCenterContacts":null,"chatContacts":null,"universityContacts":null}]}
{"countryContacts":[{"languageTag":"cs","phoneContacts":[{"pinned":true,"title":"Linka bezpečí","tel":"116 111","subtitle":"Nonstop zdarma","runtimeType":"default"},{"pinned":true,"title":"Linka psychické pomoci","tel":"116 123","subtitle":"Nonstop zdarma","runtimeType":"default"},{"title":"Modrá linka","subtitle":"Nonstop","subPhoneContacts":[{"title":"Mobil","tel":"731 197 477","action":"phone"},{"title":"Mobil","tel":"608 902 410","action":"phone"}],"runtimeType":"subList"},{"pinned":false,"title":"Linka pro rodinu a školu","tel":"116 000","subtitle":"Nonstop zdarma","runtimeType":"default"},{"pinned":false,"title":"Pražská linka důvěry","tel":"222 580 697","subtitle":"Nonstop","runtimeType":"default"},{"pinned":false,"title":"Linka důvěry CKI Bohnice","tel":"284 016 666","subtitle":"Nonstop","runtimeType":"default"},{"title":"Linka důvěry Dětského krizového centra","subtitle":"Nonstop","subPhoneContacts":[{"title":"Telefon","tel":"241 484 149","action":"phone"},{"title":"Mobil","tel":"777 715 215","action":"phone"}],"runtimeType":"subList"},{"pinned":false,"title":"Linka Anabell (poruchy přijmu potravy)","tel":"774 467 293","subtitle":"Pondělí\t8–16 hodin\nÚterý\t10–18 hodin\nStředa–pátek\t8–16 hodin","runtimeType":"default"}],"crisisCenterContacts":[{"title":"CrisisCenterContact TODO"}],"chatContacts":[{"title":"Poradna 1 - TODO","subtitle":null},{"title":"Poradna 2 - TODO","subtitle":null}],"universityContacts":[{"title":"Uni Contacts TODO"}]},{"languageTag":"en","phoneContacts":[{"pinned":true,"title":"TODO number 1","tel":"116 111","subtitle":"Nonstop","runtimeType":"default"},{"pinned":false,"title":"Example 2","tel":"123 456","subtitle":null,"runtimeType":"default"}],"crisisCenterContacts":null,"chatContacts":null,"universityContacts":null},{"languageTag":"sk","phoneContacts":[{"pinned":true,"title":"Linka detskej istoty","tel":"116 123","subtitle":"Nonstop zdarma","runtimeType":"default"},{"pinned":false,"title":"Krízová linka pomoci","tel":"0800 500 333","subtitle":"Nonstop zdarma","runtimeType":"default"},{"pinned":false,"title":"Liga za duševné zdravie Slovensko","tel":"0800 800 566","subtitle":"Nonstop zdarma","runtimeType":"default"}],"crisisCenterContacts":null,"chatContacts":null,"universityContacts":null}]}
48 changes: 31 additions & 17 deletions lib/games/math/math_game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,32 @@ class _MathGameScreenState extends State<MathGameScreen> {
late MathEquation _equation;

final TextEditingController _textEditingController = TextEditingController();
final FocusNode _focusNode = FocusNode();

final _lottieCacheManager = registry.get<LottieCacheManager>();

static const _winAnimDuration = Duration(milliseconds: 800);
static const _answerEvaluationDuration = Duration(milliseconds: 200);

void _setAnswerResultState(MathAnswerResultState state) {
if (state != _answerResultState) {
setState(() => _answerResultState = state);
}
}

Future<void> _evaluateEquation(String textInput) async {
Future<void> _evaluateEquation(String textInput, {bool isInputActionFromButton = false}) async {
if (textInput.isEmpty) return;
await Future.delayed(const Duration(milliseconds: 200));
if (isInputActionFromButton) await Future.delayed(_answerEvaluationDuration);
if (_equation.isValid(textInput)) {
_setAnswerResultState(MathAnswerResultState.correct);
if (mounted) _setAnswerResultState(MathAnswerResultState.correct);
await Future.delayed(_winAnimDuration);
if (mounted) _generateNewEquation();
} else {
_setAnswerResultState(MathAnswerResultState.wrong);
if (mounted) {
_textEditingController.clear();
_setAnswerResultState(MathAnswerResultState.wrong);
if (!isInputActionFromButton) _focusNode.requestFocus();
}
}
}

Expand All @@ -66,6 +76,9 @@ class _MathGameScreenState extends State<MathGameScreen> {
_answerResultState = MathAnswerResultState.notAnsweredYet;
_equation = MathEquation.generate();
});
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _focusNode.requestFocus();
});
}

@override
Expand Down Expand Up @@ -108,6 +121,7 @@ class _MathGameScreenState extends State<MathGameScreen> {
Expanded(
child: TextField(
textInputAction: TextInputAction.done,
focusNode: _focusNode,
enabled: !_answerResultState.isCorrect,
keyboardType: TextInputType.number,
controller: _textEditingController,
Expand All @@ -129,19 +143,19 @@ class _MathGameScreenState extends State<MathGameScreen> {
valueListenable: _textEditingController,
builder: (_, textEditingValue, __) {
final textInput = textEditingValue.text;
return _answerResultState.isCorrect
? NepanikarButton(
onTap: () => _generateNewEquation(),
trailingIcon: Assets.icons.navigation.chevronRight,
// TODO: l10n
text: 'Další',
)
: NepanikarButton.async(
onTapAsync: () async => _evaluateEquation(textInput),
trailingIcon: Assets.icons.navigation.chevronRight,
enabled: textInput.isNotEmpty,
text: context.l10n.submit,
);
return Visibility(
maintainState: true,
maintainAnimation: true,
maintainSize: true,
visible: !_answerResultState.isCorrect,
child: NepanikarButton.async(
onTapAsync: () async =>
_evaluateEquation(textInput, isInputActionFromButton: true),
trailingIcon: Assets.icons.navigation.chevronRight,
enabled: textInput.isNotEmpty,
text: context.l10n.submit,
),
);
},
),
],
Expand Down
9 changes: 9 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ class Nepanikar extends StatelessWidget {
supportedLocales: AppLocalizations.supportedLocales,
locale: context.watch<LocalizationProvider>().locale,
routerConfig: _goRouter,
builder: (context, child) {
return child != null
? MediaQuery(
// To not influence app's font size by the system font size.
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: child,
)
: const SizedBox.shrink();
},
);
}
}
58 changes: 32 additions & 26 deletions lib/screens/main/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,39 @@ class HomeScreen extends StatelessWidget {
body: SafeArea(
child: CustomScrollView(
slivers: [
SliverAppBar(
pinned: true,
floating: true,
expandedHeight: 92.0,
collapsedHeight: 60,
elevation: 2,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
const SizedBox(
width: 6,
),
Assets.icons.logo.svg(),
const SizedBox(
width: 10,
),
Text(
context.l10n.app_name,
style: NepanikarFonts.title3.copyWith(fontSize: 18.6),
SliverPadding(
padding: const EdgeInsets.all(8),
sliver: SliverAppBar(
pinned: true,
floating: true,
expandedHeight: 92.0,
collapsedHeight: 60,
elevation: 2,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(
width: 6,
),
Assets.icons.logo.svg(),
const SizedBox(
width: 10,
),
Text(
context.l10n.app_name,
style: NepanikarFonts.title3.copyWith(fontSize: 18.6),
),
],
),
],
),
QuickHelpButton(show: showQuickHelpButton),
],
),
if (showQuickHelpButton) const Expanded(child: QuickHelpButton()),
],
),
),
),
const SliverPadding(
Expand Down
13 changes: 6 additions & 7 deletions lib/screens/main/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ class _MainScreenState extends State<MainScreen> {
return BottomNavigationBarItem(
icon: Column(
children: [
if (isSelected)
Padding(
padding: const EdgeInsets.only(bottom: 6),
child: SvgPicture.asset(
Assets.icons.marker.path,
color: NepanikarColors.primarySwatch.shade800,
),
Padding(
padding: const EdgeInsets.only(bottom: 6),
child: SvgPicture.asset(
Assets.icons.marker.path,
color: isSelected ? NepanikarColors.primarySwatch.shade800 : Colors.transparent,
),
),
SvgPicture.asset(
svgIconPath,
color: isSelected
Expand Down
60 changes: 29 additions & 31 deletions lib/widgets/contacts/quick_help_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,41 @@ import 'package:nepanikar/router/routes.dart';
import 'package:nepanikar/screens/contacts/phone_contacts_screen.dart';

class QuickHelpButton extends StatelessWidget {
const QuickHelpButton({
super.key,
required this.show,
});

final bool show;
const QuickHelpButton({super.key});

@override
Widget build(BuildContext context) {
return !show
? const SizedBox.shrink()
: SizedBox(
width: 163,
child: Material(
borderRadius: BorderRadius.circular(12),
color: NepanikarColors.secondary,
child: InkWell(
onTap: () => context.push(const PhoneContactsRoute().location),
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
child: Row(
children: [
Assets.icons.phone.svg(width: 20, height: 20, color: Colors.white),
const SizedBox(width: 8),
Flexible(
child: Text(
// TODO: l10n
'Rychlá pomoc',
style: NepanikarFonts.bodyHeavy.copyWith(color: Colors.white),
),
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
child: Material(
color: NepanikarColors.secondary,
clipBehavior: Clip.antiAlias,
borderRadius: BorderRadius.circular(12),
child: InkWell(
onTap: () => context.push(const PhoneContactsRoute().location),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Assets.icons.phone.svg(width: 20, height: 20, color: Colors.white),
const SizedBox(width: 8),
Flexible(
child: Text(
// TODO: l10n
'Rychlá pomoc',
style: NepanikarFonts.bodyHeavy.copyWith(color: Colors.white),
),
],
),
),
],
),
),
),
);
),
),
],
);
}
}
10 changes: 5 additions & 5 deletions lib/widgets/long_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ class LongTile extends StatelessWidget {
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: const Color(0xff280446).withOpacity(0.08),
blurRadius: 32,
offset: const Offset(0, 8), // changes position of shadow
),
BoxShadow(
color: const Color(0xff2C0B4A).withOpacity(0.04),
blurRadius: 4,
offset: const Offset(0, 2), // changes position of shadow
),
BoxShadow(
color: const Color(0xff280446).withOpacity(0.12),
blurRadius: 48,
offset: const Offset(0, 16), // changes position of shadow
),
],
),
child: Material(
Expand Down
12 changes: 8 additions & 4 deletions lib/widgets/nepanikar_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ class _NepanikarButtonState extends State<NepanikarButton> with SingleTickerProv

Future<void> _onTap() async {
if (widget.buttonType.isAsync) {
if (mounted) setState(() => _isLoading = true);
unawaited(_animController.repeat());
if (mounted) {
setState(() => _isLoading = true);
unawaited(_animController.repeat());
}
await widget.onTapAsync?.call();
_animController.reset();
if (mounted) setState(() => _isLoading = false);
if (mounted) {
_animController.reset();
setState(() => _isLoading = false);
}
} else {
widget.onTap?.call();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ const _phoneContacts = <PhoneContact>[
subtitle: '''
Pondělí\t8–16 hodin
Úterý\t10–18 hodin
Středa–pátek\t8–16 hodin
''',
Středa–pátek\t8–16 hodin''',
tel: '774 467 293',
),
];
Expand Down

0 comments on commit bb3e0bf

Please sign in to comment.