Skip to content

Commit

Permalink
Merge pull request #5 from kackogut/feature/form_errors
Browse files Browse the repository at this point in the history
Feature/form validation
  • Loading branch information
kackogut authored Sep 19, 2023
2 parents ec7494f + 1543fe0 commit cb10afc
Show file tree
Hide file tree
Showing 16 changed files with 426 additions and 54 deletions.
104 changes: 104 additions & 0 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# sol_pay_gen
# Solana Pay QR generator

QR code generator for Solana Pay

## Getting Started
## Checklist

This project is a starting point for a Flutter application.
- ✅ Validation

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
- 🚧 Download QR code
- 🚧 SPL token picker
- 🚧 Upload custom icon
- 🚧 Adaptive layout
- 🚧 How it works page
- 🚧 Transaction request
- 🚧 Transactions history
22 changes: 22 additions & 0 deletions lib/data/base/text_value.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import '../error/input_error.dart';

class TextValue {
TextValue({
this.text = "",
this.error,
});

final String text;
final InputError? error;

TextValue copyWith({
String? text,
InputError? error,
}) =>
TextValue(
text: text ?? this.text,
error: error ?? this.error,
);

bool isValid() => error == null;
}
28 changes: 28 additions & 0 deletions lib/data/error/input_error.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
abstract class InputError {
abstract String text;
}

class NotANumber extends InputError {
@override
String text = "Field must be a number";
}

class EmptyAmount extends InputError {
@override
String text = "Amount must be more than 0 if present";
}

class RequiredAmount extends InputError {
@override
String text = "Field is required";
}

class KeyNotBase58Encoded extends InputError {
@override
String text = "Invalid value, must be base58 encoded";
}

class KeyLengthInvalid extends InputError {
@override
String text = "Key value must be between 32 and 44 characters";
}
14 changes: 7 additions & 7 deletions lib/data/solana_pay_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class SolanaPayRequest {
this.splToken,
});

String address;
String? label;
String? splToken;
String? message;
String? amount;
String? reference;
String? memo;
final String address;
final String? label;
final String? splToken;
final String? message;
final String? amount;
final String? reference;
final String? memo;
}
11 changes: 7 additions & 4 deletions lib/design/input/base_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@ class BaseInput extends StatelessWidget {
final ValueChanged<String>? _onChanged;
final TextInputType? _keyboardType;
final bool _focusable;
final String? _error;

const BaseInput({
super.key,
required labelText,
required onChanged,
keyboardType,
focusable,
error,
}) : _labelText = labelText,
_onChanged = onChanged,
_keyboardType = keyboardType,
_focusable = focusable ?? true;
_focusable = focusable ?? true,
_error = error;

@override
Widget build(BuildContext context) {
return TextField(
decoration: InputDecoration(
border: const OutlineInputBorder(),
labelText: _labelText,
),
border: const OutlineInputBorder(),
labelText: _labelText,
errorText: _error),
onChanged: _onChanged,
keyboardType: _keyboardType,
focusNode: _focusable ? null : AlwaysDisabledFocusNode(),
Expand Down
11 changes: 7 additions & 4 deletions lib/di/blocs_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:sol_pay_gen/domain/generate_transfer_request_qr_use_case.dart';
import 'package:sol_pay_gen/feature/qr/bloc/qr_generator_cubit.dart';
import 'package:sol_pay_gen/validator/keys_validator.dart';
import 'package:sol_pay_gen/validator/number_validator.dart';

import '../data/transfer/transfer_request_repository.dart';
import '../feature/input/bloc/parameters_input_cubit.dart';

MultiBlocProvider getBlocProviders({required StatelessWidget child}) {
ParametersInputCubit parametersInputCubit = ParametersInputCubit();

return MultiBlocProvider(
providers: [
BlocProvider<ParametersInputCubit>(
create: (_) => parametersInputCubit,
create: (BuildContext context) => ParametersInputCubit(
context.read<NumberValidator>(),
context.read<KeysValidator>(),
),
),
BlocProvider<QrGeneratorCubit>(
create: (BuildContext context) => QrGeneratorCubit(
generateTransferRequestQrUseCase: GenerateTransferRequestQrUseCase(
context.read<TransferRequestRepository>(),
),
parametersInputCubit: parametersInputCubit,
parametersInputCubit: context.read<ParametersInputCubit>(),
),
)
],
Expand Down
Loading

0 comments on commit cb10afc

Please sign in to comment.