Skip to content

Commit

Permalink
Added input formatters structure in Mirai to support input formatters…
Browse files Browse the repository at this point in the history
… in text fields.
  • Loading branch information
i-asimkhan committed Apr 12, 2023
1 parent f91d483 commit 3f4853c
Show file tree
Hide file tree
Showing 13 changed files with 481 additions and 14 deletions.
46 changes: 46 additions & 0 deletions examples/mirai_gallery/assets/json/text_field_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
},
"labelText": "Name*"
},
"inputFormatters": [
{
"type": "allow",
"rule": "[a-zA-Z]"
}
],
"readOnly": false,
"enabled": true
},
Expand Down Expand Up @@ -75,6 +81,11 @@
},
"labelText": "Phone number*"
},
"inputFormatters": [
{
"type": "digitsOnly"
}
],
"readOnly": false,
"enabled": true
},
Expand Down Expand Up @@ -110,6 +121,41 @@
"type": "sizedBox",
"height": 24
},
{
"type": "textField",
"maxLines": 1,
"keyboardType": "text",
"textInputAction": "done",
"textAlign": "start",
"textCapitalization": "none",
"textDirection": "ltr",
"textAlignVertical": "top",
"obscureText": false,
"decoration": {
"filled": true,
"icon": {
"type": "icon",
"iconType": "material",
"icon": "credit_card",
"size": 24
},
"hintText": "XXXX XXXX XXXX XXXX",
"labelText": "Credit Card"
},
"inputFormatters": [
{
"type": "masked",
"rule": "XXXX-XXXX-XXXX-XXXX",
"value": "-"
}
],
"readOnly": false,
"enabled": true
},
{
"type": "sizedBox",
"height": 24
},
{
"type": "sizedBox",
"height": 100,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mirai/src/utils/input_formatters.dart';

part 'mirai_input_formatter.freezed.dart';
part 'mirai_input_formatter.g.dart';

@freezed
class MiraiInputFormatter with _$MiraiInputFormatter {
const factory MiraiInputFormatter({
required InputFormatterType type,
String? rule,
String? value,
}) = _MiraiInputFormatter;

factory MiraiInputFormatter.fromJson(Map<String, dynamic> json) =>
_$MiraiInputFormatterFromJson(json);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark

part of 'mirai_input_formatter.dart';

// **************************************************************************
// FreezedGenerator
// **************************************************************************

T _$identity<T>(T value) => value;

final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');

MiraiInputFormatter _$MiraiInputFormatterFromJson(Map<String, dynamic> json) {
return _MiraiInputFormatter.fromJson(json);
}

/// @nodoc
mixin _$MiraiInputFormatter {
InputFormatterType get type => throw _privateConstructorUsedError;
String? get rule => throw _privateConstructorUsedError;
String? get value => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$MiraiInputFormatterCopyWith<MiraiInputFormatter> get copyWith =>
throw _privateConstructorUsedError;
}

/// @nodoc
abstract class $MiraiInputFormatterCopyWith<$Res> {
factory $MiraiInputFormatterCopyWith(
MiraiInputFormatter value, $Res Function(MiraiInputFormatter) then) =
_$MiraiInputFormatterCopyWithImpl<$Res, MiraiInputFormatter>;
@useResult
$Res call({InputFormatterType type, String? rule, String? value});
}

/// @nodoc
class _$MiraiInputFormatterCopyWithImpl<$Res, $Val extends MiraiInputFormatter>
implements $MiraiInputFormatterCopyWith<$Res> {
_$MiraiInputFormatterCopyWithImpl(this._value, this._then);

// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;

@pragma('vm:prefer-inline')
@override
$Res call({
Object? type = null,
Object? rule = freezed,
Object? value = freezed,
}) {
return _then(_value.copyWith(
type: null == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as InputFormatterType,
rule: freezed == rule
? _value.rule
: rule // ignore: cast_nullable_to_non_nullable
as String?,
value: freezed == value
? _value.value
: value // ignore: cast_nullable_to_non_nullable
as String?,
) as $Val);
}
}

/// @nodoc
abstract class _$$_MiraiInputFormatterCopyWith<$Res>
implements $MiraiInputFormatterCopyWith<$Res> {
factory _$$_MiraiInputFormatterCopyWith(_$_MiraiInputFormatter value,
$Res Function(_$_MiraiInputFormatter) then) =
__$$_MiraiInputFormatterCopyWithImpl<$Res>;
@override
@useResult
$Res call({InputFormatterType type, String? rule, String? value});
}

/// @nodoc
class __$$_MiraiInputFormatterCopyWithImpl<$Res>
extends _$MiraiInputFormatterCopyWithImpl<$Res, _$_MiraiInputFormatter>
implements _$$_MiraiInputFormatterCopyWith<$Res> {
__$$_MiraiInputFormatterCopyWithImpl(_$_MiraiInputFormatter _value,
$Res Function(_$_MiraiInputFormatter) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
@override
$Res call({
Object? type = null,
Object? rule = freezed,
Object? value = freezed,
}) {
return _then(_$_MiraiInputFormatter(
type: null == type
? _value.type
: type // ignore: cast_nullable_to_non_nullable
as InputFormatterType,
rule: freezed == rule
? _value.rule
: rule // ignore: cast_nullable_to_non_nullable
as String?,
value: freezed == value
? _value.value
: value // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}

/// @nodoc
@JsonSerializable()
class _$_MiraiInputFormatter implements _MiraiInputFormatter {
const _$_MiraiInputFormatter({required this.type, this.rule, this.value});

factory _$_MiraiInputFormatter.fromJson(Map<String, dynamic> json) =>
_$$_MiraiInputFormatterFromJson(json);

@override
final InputFormatterType type;
@override
final String? rule;
@override
final String? value;

@override
String toString() {
return 'MiraiInputFormatter(type: $type, rule: $rule, value: $value)';
}

@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$_MiraiInputFormatter &&
(identical(other.type, type) || other.type == type) &&
(identical(other.rule, rule) || other.rule == rule) &&
(identical(other.value, value) || other.value == value));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, type, rule, value);

@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$_MiraiInputFormatterCopyWith<_$_MiraiInputFormatter> get copyWith =>
__$$_MiraiInputFormatterCopyWithImpl<_$_MiraiInputFormatter>(
this, _$identity);

@override
Map<String, dynamic> toJson() {
return _$$_MiraiInputFormatterToJson(
this,
);
}
}

abstract class _MiraiInputFormatter implements MiraiInputFormatter {
const factory _MiraiInputFormatter(
{required final InputFormatterType type,
final String? rule,
final String? value}) = _$_MiraiInputFormatter;

factory _MiraiInputFormatter.fromJson(Map<String, dynamic> json) =
_$_MiraiInputFormatter.fromJson;

@override
InputFormatterType get type;
@override
String? get rule;
@override
String? get value;
@override
@JsonKey(ignore: true)
_$$_MiraiInputFormatterCopyWith<_$_MiraiInputFormatter> get copyWith =>
throw _privateConstructorUsedError;
}

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

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mirai/src/parsers/mirai_input_decoration/mirai_input_decoration.dart';
import 'package:mirai/src/parsers/mirai_input_formatters/mirai_input_formatter.dart';
import 'package:mirai/src/parsers/mirai_text_style/mirai_text_style.dart';
import 'package:mirai/src/utils/text_input_utils.dart';

Expand Down Expand Up @@ -36,6 +37,7 @@ class MiraiTextField with _$MiraiTextField {
double? cursorHeight,
String? cursorColor,
String? hintText,
@Default([]) List<MiraiInputFormatter> inputFormatters,
}) = _MiraiTextField;

factory MiraiTextField.fromJson(Map<String, dynamic> json) =>
Expand Down
Loading

0 comments on commit 3f4853c

Please sign in to comment.