Skip to content

Commit

Permalink
fix: input styles
Browse files Browse the repository at this point in the history
  • Loading branch information
parodyBit committed Nov 19, 2024
1 parent cbb9b07 commit 0ebb379
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 26 deletions.
13 changes: 6 additions & 7 deletions lib/screens/create_wallet/enc_xprv_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:my_wit_wallet/screens/create_wallet/bloc/create_wallet_bloc.dart
import 'package:my_wit_wallet/screens/create_wallet/create_wallet_screen.dart';
import 'package:my_wit_wallet/shared/locator.dart';
import 'package:my_wit_wallet/util/storage/database/wallet.dart';
import 'package:my_wit_wallet/widgets/inputs/input_xprv.dart';
import 'package:my_wit_wallet/widgets/labeled_form_entry.dart';
import 'package:my_wit_wallet/widgets/suffix_icon_button.dart';
import 'package:my_wit_wallet/widgets/inputs/input_password.dart';
Expand Down Expand Up @@ -99,12 +100,10 @@ class EnterXprvCardState extends State<EnterEncryptedXprvCard>
}

void setXprv(String value) {
setState(() {
xprv = XprvInput.dirty(
xprvType: _xprvType,
allowValidation: validationUtils.isFormUnFocus(_formFocusElements),
value: value);
});
}

void clearForm() {
Expand Down Expand Up @@ -134,7 +133,9 @@ class EnterXprvCardState extends State<EnterEncryptedXprvCard>
Widget _buildXprvInput() {
final theme = Theme.of(context);
final extendedTheme = theme.extension<ExtendedTheme>()!;
return TextField(
return InputXprv(
setXprvCallback: setXprv,
route: CreateWalletScreen.route,
decoration: InputDecoration(
hintStyle: extendedTheme.monoLargeText!.copyWith(
color: theme.textTheme.titleMedium!.color!.withOpacity(0.5)),
Expand Down Expand Up @@ -170,12 +171,10 @@ class EnterXprvCardState extends State<EnterEncryptedXprvCard>
errorText: xprv.error,
),
keyboardType: TextInputType.text,
textInputAction: TextInputAction.go,
focusNode: _textFocusNode,
style: extendedTheme.monoLargeText,
maxLines: 3,
controller: _textController,
onSubmitted: (value) async {
styledTextController: _textController,
onFieldSubmitted: (value) async {
if (_xprvType == CreateWalletType.encryptedXprv) {
_passFocusNode.requestFocus();
} else {
Expand Down
10 changes: 7 additions & 3 deletions lib/widgets/inputs/input_address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ class InputAddress extends InputText {
super.inputFormatters,
super.decoration,
super.maxLines = 1,
this.setAddressCallback,
});

final String? route;
final void Function(String, {bool? validate})? setAddressCallback;
@override
_InputAddressState createState() => _InputAddressState();
}
Expand Down Expand Up @@ -67,16 +69,17 @@ class _InputAddressState extends State<InputAddress> {

_handleQrAddressResults(String value) {
widget.styledTextController.text = value;
widget.setAddressCallback!(value);
}

Widget build(BuildContext context) {
final theme = Theme.of(context);
final extendedTheme = theme.extension<ExtendedTheme>()!;

widget.styledTextController.setStyle(
extendedTheme.monoMediumText!
extendedTheme.monoLargeText!
.copyWith(color: theme.textTheme.bodyMedium!.color),
extendedTheme.monoMediumText!.copyWith(color: Colors.black),
extendedTheme.monoLargeText!.copyWith(color: Colors.black),
);

return Column(
Expand All @@ -87,7 +90,8 @@ class _InputAddressState extends State<InputAddress> {
context: context,
decoration: widget.decoration ??
InputDecoration(
hintStyle: extendedTheme.monoMediumText,
hintStyle: extendedTheme.monoLargeText!
.copyWith(color: theme.textTheme.bodyMedium!.color),
hintText: localization.recipientAddress,
suffixIcon: !Platform.isWindows && !Platform.isLinux
? Semantics(
Expand Down
16 changes: 8 additions & 8 deletions lib/widgets/inputs/input_authorization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'package:my_wit_wallet/widgets/witnet/transactions/value_transfer/create_

import 'package:my_wit_wallet/theme/extended_theme.dart';
import 'package:my_wit_wallet/util/get_localization.dart';
import '../../util/storage/scanned_content.dart';
import 'input_text.dart';
import 'package:my_wit_wallet/util/storage/scanned_content.dart';
import 'package:my_wit_wallet/widgets/inputs/input_text.dart';

class InputAuthorization extends InputText {
InputAuthorization({
Expand Down Expand Up @@ -38,7 +38,7 @@ class _InputAuthorizationState extends State<InputAuthorization> {
FocusNode _scanQrFocusNode = FocusNode();
bool isScanQrFocused = false;
ScannedContent scannedContent = ScannedContent();

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -71,8 +71,9 @@ class _InputAuthorizationState extends State<InputAuthorization> {
final extendedTheme = theme.extension<ExtendedTheme>()!;

widget.styledTextController.setStyle(
extendedTheme.monoMediumText!,
extendedTheme.monoMediumText!.copyWith(color: Colors.black),
extendedTheme.monoLargeText!
.copyWith(color: theme.textTheme.bodyMedium!.color),
extendedTheme.monoLargeText!.copyWith(color: Colors.black),
);

return Column(
Expand All @@ -83,9 +84,8 @@ class _InputAuthorizationState extends State<InputAuthorization> {
context: context,
decoration: widget.decoration ??
InputDecoration(
hintStyle: extendedTheme.monoMediumText!.copyWith(
color: extendedTheme.monoMediumText!.color!
.withOpacity(0.5)),
hintStyle: extendedTheme.monoLargeText!
.copyWith(color: theme.textTheme.bodyMedium!.color),
hintText: localization.authorizationInputHint,
contentPadding: EdgeInsets.all(16),
suffixIcon: !Platform.isWindows && !Platform.isLinux
Expand Down
116 changes: 116 additions & 0 deletions lib/widgets/inputs/input_xprv.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:my_wit_wallet/widgets/suffix_icon_button.dart';
import 'package:my_wit_wallet/widgets/witnet/transactions/value_transfer/create_dialog_box/qr_scanner.dart';

import 'package:my_wit_wallet/theme/extended_theme.dart';
import 'package:my_wit_wallet/util/get_localization.dart';
import 'package:my_wit_wallet/util/storage/scanned_content.dart';
import 'input_text.dart';

class InputXprv extends InputText {
InputXprv({
required super.focusNode,
required super.styledTextController,
super.prefixIcon,
super.errorText,
super.validator,
super.hint,
super.keyboardType,
super.obscureText = false,
required this.route,
super.onChanged,
super.onEditingComplete,
super.onFieldSubmitted,
super.onTapOutside,
super.onTap,
super.onSuffixTap,
super.maxLines = 3,
this.setXprvCallback,
super.decoration,
});

@override
_InputXprvState createState() => _InputXprvState();
final String route;
final void Function(String)? setXprvCallback;
}

class _InputXprvState extends State<InputXprv> {
FocusNode _scanQrFocusNode = FocusNode();
bool isScanQrFocused = false;
ScannedContent scannedContent = ScannedContent();
@override
void initState() {
super.initState();
if (scannedContent.scannedContent != null) {
_handleQrAddressResults(scannedContent.scannedContent!);
}
widget.focusNode.addListener(widget.onFocusChange);
_scanQrFocusNode.addListener(_handleQrFocus);
}

_handleQrAddressResults(String value) {
widget.styledTextController.text = value;
widget.setXprvCallback!(value);
}

_handleQrFocus() {
setState(() {
isScanQrFocused = _scanQrFocusNode.hasFocus;
});
}

@override
void dispose() {
super.dispose();
widget.focusNode.removeListener(widget.onFocusChange);
_scanQrFocusNode.removeListener(_handleQrFocus);
}

Widget build(BuildContext context) {
final theme = Theme.of(context);
final extendedTheme = theme.extension<ExtendedTheme>()!;

widget.styledTextController.setStyle(
extendedTheme.monoLargeText!
.copyWith(color: theme.textTheme.bodyMedium!.color),
extendedTheme.monoLargeText!.copyWith(color: Colors.black),
);

return Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.max,
children: [
widget.buildInput(
context: context,
decoration: widget.decoration ??
InputDecoration(
hintStyle: extendedTheme.monoMediumText!
.copyWith(color: theme.textTheme.bodyMedium!.color),
hintText: localization.authorizationInputHint,
contentPadding: EdgeInsets.all(16),
suffixIcon: !Platform.isWindows && !Platform.isLinux
? Semantics(
label: localization.scanQrCodeLabel,
child: SuffixIcon(
focusNode: _scanQrFocusNode,
isFocus: isScanQrFocused,
icon: FontAwesomeIcons.qrcode,
onPressed: () => {
{
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => QrScanner(
currentRoute: widget.route,
onChanged: (_value) => {})))
},
},
))
: null,
errorText: widget.errorText,
),
),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,10 @@ class RecipientStepState extends State<RecipientStep>
}

void setAddress(String value, {bool? validate}) {
setState(() {
_address = AddressInput.dirty(
value: value,
allowValidation:
validate ?? validationUtils.isFormUnFocus([_addressFocusNode]));
});
_address = AddressInput.dirty(
value: value,
allowValidation:
validate ?? validationUtils.isFormUnFocus([_addressFocusNode]));
}

void setAmount(String value, {bool? validate}) {
Expand All @@ -204,13 +202,11 @@ class RecipientStepState extends State<RecipientStep>
}

void setAuthorization(String value, {bool? validate}) {
setState(() {
_authorization = AuthorizationInput.dirty(
withdrawerAddress: _address.value,
allowValidation:
validate ?? validationUtils.isFormUnFocus(_formFocusElements()),
value: value);
});
}

void _setSavedTxData() {
Expand Down Expand Up @@ -501,6 +497,7 @@ class RecipientStepState extends State<RecipientStep>
onTapOutside: (event) {
_addressFocusNode.unfocus();
},
setAddressCallback: setAddress,
))
];
}
Expand Down Expand Up @@ -528,6 +525,7 @@ class RecipientStepState extends State<RecipientStep>
onTapOutside: (event) {
_addressFocusNode.unfocus();
},
setAddressCallback: setAddress,
),
),
];
Expand Down

0 comments on commit 0ebb379

Please sign in to comment.