2024-06-30 20:25:36 +02:00
|
|
|
// SPDX-FileCopyrightText: (C) 2024 Matyáš Caras
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-12-29 21:39:54 +01:00
|
|
|
// ignore_for_file: public_member_api_docs
|
|
|
|
|
2023-09-08 11:50:21 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:prasule/pw/platformwidget.dart';
|
|
|
|
|
2023-12-29 21:39:54 +01:00
|
|
|
/// A [PlatformWidget] implementation of a text field
|
2024-07-19 17:34:45 +02:00
|
|
|
class PlatformField extends PlatformWidget<TextFormField, CupertinoTextField> {
|
|
|
|
const PlatformField(
|
|
|
|
{super.key,
|
|
|
|
this.controller,
|
|
|
|
this.enabled,
|
|
|
|
this.labelText,
|
|
|
|
this.obscureText = false,
|
|
|
|
this.autocorrect = false,
|
|
|
|
this.keyboardType,
|
|
|
|
this.inputFormatters = const [],
|
|
|
|
this.onChanged,
|
|
|
|
this.autofillHints,
|
|
|
|
this.textStyle,
|
|
|
|
this.textAlign = TextAlign.start,
|
|
|
|
this.maxLines = 1,
|
|
|
|
this.focusNode,
|
|
|
|
this.inputBorder = const OutlineInputBorder(),
|
|
|
|
this.suffix,
|
|
|
|
this.prefix,
|
|
|
|
this.validator});
|
2023-09-08 11:50:21 +02:00
|
|
|
final TextEditingController? controller;
|
|
|
|
final bool? enabled;
|
|
|
|
final bool obscureText;
|
|
|
|
final String? labelText;
|
|
|
|
final bool autocorrect;
|
|
|
|
final TextInputType? keyboardType;
|
|
|
|
final List<TextInputFormatter> inputFormatters;
|
|
|
|
final void Function(String)? onChanged;
|
|
|
|
final List<String>? autofillHints;
|
|
|
|
final TextStyle? textStyle;
|
|
|
|
final TextAlign textAlign;
|
2023-11-01 17:58:05 +01:00
|
|
|
final int? maxLines;
|
2024-01-22 19:20:41 +01:00
|
|
|
final InputBorder inputBorder;
|
|
|
|
final FocusNode? focusNode;
|
2024-01-29 18:47:01 +01:00
|
|
|
final Widget? suffix;
|
|
|
|
final Widget? prefix;
|
2024-07-19 17:34:45 +02:00
|
|
|
final String? Function(String?)? validator;
|
2023-09-08 11:50:21 +02:00
|
|
|
|
|
|
|
@override
|
2024-07-19 17:34:45 +02:00
|
|
|
TextFormField createAndroidWidget(BuildContext context) => TextFormField(
|
2023-09-08 11:50:21 +02:00
|
|
|
textAlign: textAlign,
|
|
|
|
controller: controller,
|
|
|
|
enabled: enabled,
|
|
|
|
obscureText: obscureText,
|
2023-09-29 11:38:21 +02:00
|
|
|
decoration: InputDecoration(
|
2023-12-29 21:39:54 +01:00
|
|
|
labelText: labelText,
|
2024-01-22 19:20:41 +01:00
|
|
|
border: inputBorder,
|
2024-01-29 18:47:01 +01:00
|
|
|
suffix: suffix,
|
|
|
|
prefix: prefix,
|
2023-12-29 21:39:54 +01:00
|
|
|
),
|
2023-09-08 11:50:21 +02:00
|
|
|
autocorrect: autocorrect,
|
|
|
|
keyboardType: keyboardType,
|
2024-01-22 19:20:41 +01:00
|
|
|
focusNode: focusNode,
|
2023-09-08 11:50:21 +02:00
|
|
|
style: textStyle,
|
|
|
|
inputFormatters: inputFormatters,
|
|
|
|
onChanged: onChanged,
|
|
|
|
autofillHints: autofillHints,
|
2023-11-01 17:58:05 +01:00
|
|
|
maxLines: maxLines,
|
2024-07-19 17:34:45 +02:00
|
|
|
validator: validator,
|
2023-09-08 11:50:21 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
|
|
|
CupertinoTextField createIosWidget(BuildContext context) =>
|
|
|
|
CupertinoTextField(
|
|
|
|
textAlign: textAlign,
|
|
|
|
controller: controller,
|
2023-11-01 17:58:05 +01:00
|
|
|
enabled: enabled ?? true,
|
2023-09-08 11:50:21 +02:00
|
|
|
obscureText: obscureText,
|
2024-01-09 00:31:03 +01:00
|
|
|
placeholder: labelText,
|
2023-09-08 11:50:21 +02:00
|
|
|
autocorrect: autocorrect,
|
|
|
|
keyboardType: keyboardType,
|
|
|
|
inputFormatters: inputFormatters,
|
|
|
|
onChanged: onChanged,
|
2024-01-22 19:20:41 +01:00
|
|
|
focusNode: focusNode,
|
2023-11-01 17:58:05 +01:00
|
|
|
maxLines: maxLines,
|
2023-09-08 11:50:21 +02:00
|
|
|
style: textStyle,
|
2024-01-29 18:47:01 +01:00
|
|
|
prefix: prefix,
|
|
|
|
suffix: suffix,
|
2023-09-08 11:50:21 +02:00
|
|
|
);
|
|
|
|
}
|