Skip to content

Commit

Permalink
Extract inputs to separate components
Browse files Browse the repository at this point in the history
  • Loading branch information
kackogut committed Sep 25, 2023
1 parent 489c634 commit 0d5d0dc
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 70 deletions.
177 changes: 108 additions & 69 deletions lib/feature/input/parameters_input_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import 'package:sol_pay_gen/feature/input/bloc/parameters_input_cubit.dart';
import 'package:sol_pay_gen/feature/qr/bloc/qr_generator_cubit.dart';
import 'package:sol_pay_gen/feature/qr/bloc/qr_generator_state.dart';

import '../../data/base/text_value.dart';
import '../../design/input/base_input.dart';
import '../../design/sizes.dart';
import '../../design/spacings.dart';
import '../../util/strings.dart';
import '../qr/qr_code_dialog.dart';
Expand Down Expand Up @@ -37,6 +39,8 @@ class ParametersInputScreen extends StatelessWidget {
builder: (context, state) => InputBody(state: state),
),
),
floatingActionButton: _GenerateQrButton(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
);
}

Expand All @@ -46,77 +50,112 @@ class InputBody extends StatelessWidget {
final ParametersInputState state;

@override
Widget build(BuildContext context) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
Widget build(BuildContext context) => ListView(
padding: const EdgeInsets.all(Spacing.medium_150),
shrinkWrap: true,
children: [
Padding(
padding: const EdgeInsets.all(Spacing.medium_150),
child: ListView(
shrinkWrap: true,
children: [
BaseInput(
labelText: S.addressLabel.tr(),
error: state.address.error?.text,
onChanged: (address) => context
.read<ParametersInputCubit>()
.onAddressChange(address),
),
const SizedBox(height: Spacing.medium_100),
BaseInput(
labelText: S.amountLabel.tr(),
keyboardType: TextInputType.number,
error: state.amount.error?.text,
onChanged: (address) => context
.read<ParametersInputCubit>()
.onAmountChange(address),
),
const SizedBox(height: Spacing.medium_100),
BaseInput(
labelText: S.labelLabel.tr(),
onChanged: (text) =>
context.read<ParametersInputCubit>().onLabelChange(text),
),
const SizedBox(height: Spacing.medium_100),
BaseInput(
labelText: S.messageLabel.tr(),
onChanged: (text) => context
.read<ParametersInputCubit>()
.onMessageChange(text),
),
const SizedBox(height: Spacing.medium_100),
BaseInput(
labelText: S.referenceLabel.tr(),
error: state.reference.error?.text,
onChanged: (address) => context
.read<ParametersInputCubit>()
.onReferenceChange(address),
),
const SizedBox(height: Spacing.medium_100),
BaseInput(
labelText: S.memoLabel.tr(),
onChanged: (memo) =>
context.read<ParametersInputCubit>().onMemoChange(memo),
),
const SizedBox(height: Spacing.medium_100),
if (state.selectedToken != null)
SelectedTokenRow(
tokenData: state.selectedToken!,
selectableTokens: state.selectableTokens,
)
],
_AddressInput(address: state.address),
const SizedBox(height: Spacing.medium_100),
_AmountInput(amount: state.amount),
const SizedBox(height: Spacing.medium_100),
_LabelInput(),
const SizedBox(height: Spacing.medium_100),
_MessageInput(),
const SizedBox(height: Spacing.medium_100),
_ReferenceInput(reference: state.reference),
const SizedBox(height: Spacing.medium_100),
_MemoInput(),
const SizedBox(height: Spacing.medium_100),
if (state.selectedToken != null)
SelectedTokenRow(
tokenData: state.selectedToken!,
selectableTokens: state.selectableTokens,
),
),
const Spacer(),
Padding(
padding: const EdgeInsets.all(Spacing.medium_150),
child: BaseButton(
onPressed: () {
context.read<ParametersInputCubit>().onValidate();
context.read<QrGeneratorCubit>().onGenerate();
},
text: S.generateQrButtonText.tr(),
),
)
const SizedBox(height: Sizes.actionButtonSize + Spacing.medium_100),
],
);
}

class _AddressInput extends StatelessWidget {
const _AddressInput({required this.address});

final TextValue address;

@override
Widget build(BuildContext context) => BaseInput(
labelText: S.addressLabel.tr(),
error: address.error?.text,
onChanged: (address) =>
context.read<ParametersInputCubit>().onAddressChange(address),
keyboardType: TextInputType.number,
);
}

class _AmountInput extends StatelessWidget {
const _AmountInput({required this.amount});

final TextValue amount;

@override
Widget build(BuildContext context) => BaseInput(
labelText: S.amountLabel.tr(),
error: amount.error?.text,
onChanged: (address) =>
context.read<ParametersInputCubit>().onAmountChange(address),
);
}

class _LabelInput extends StatelessWidget {
@override
Widget build(BuildContext context) => BaseInput(
labelText: S.labelLabel.tr(),
onChanged: (text) =>
context.read<ParametersInputCubit>().onLabelChange(text),
);
}

class _MessageInput extends StatelessWidget {
@override
Widget build(BuildContext context) => BaseInput(
labelText: S.messageLabel.tr(),
onChanged: (text) =>
context.read<ParametersInputCubit>().onMessageChange(text),
);
}

class _ReferenceInput extends StatelessWidget {
const _ReferenceInput({required this.reference});

final TextValue reference;

@override
Widget build(BuildContext context) => BaseInput(
labelText: S.referenceLabel.tr(),
error: reference.error?.text,
onChanged: (address) =>
context.read<ParametersInputCubit>().onReferenceChange(address),
);
}

class _MemoInput extends StatelessWidget {
@override
Widget build(BuildContext context) => BaseInput(
labelText: S.memoLabel.tr(),
onChanged: (text) =>
context.read<ParametersInputCubit>().onMemoChange(text),
);
}

class _GenerateQrButton extends StatelessWidget {
@override
Widget build(BuildContext context) => Padding(
padding: const EdgeInsets.all(Spacing.medium_150),
child: BaseButton(
onPressed: () {
context.read<ParametersInputCubit>().onValidate();
context.read<QrGeneratorCubit>().onGenerate();
},
text: S.generateQrButtonText.tr(),
),
);
}
3 changes: 2 additions & 1 deletion test/data/transfer/transfer_request_repository_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:sol_pay_gen/data/transfer/transfer_request_repository.dart';
import 'package:sol_pay_gen/domain/transfer/transfer_request_data.dart';
import 'package:sol_pay_gen/domain/transfer/transfer_request_mapper.dart';
import 'package:test/test.dart';

void main() {
Expand All @@ -9,7 +10,7 @@ void main() {

final request = TransferRequestData(address: "address");

expect(repository.getLink(request), "solana:address?");
expect(repository.getLink(request.toRequestModel()), "solana:address?");
});
});
}

0 comments on commit 0d5d0dc

Please sign in to comment.