prasule/lib/pw/platformfield.dart

73 lines
2.1 KiB
Dart
Raw Normal View History

// 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';
/// A [PlatformWidget] implementation of a text field
2023-09-08 11:50:21 +02:00
class PlatformField extends PlatformWidget<TextField, 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,
});
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;
final int? maxLines;
2023-09-08 11:50:21 +02:00
@override
TextField createAndroidWidget(BuildContext context) => TextField(
textAlign: textAlign,
controller: controller,
enabled: enabled,
obscureText: obscureText,
decoration: InputDecoration(
labelText: labelText,
border: OutlineInputBorder(borderRadius: BorderRadius.circular(4)),
),
2023-09-08 11:50:21 +02:00
autocorrect: autocorrect,
keyboardType: keyboardType,
style: textStyle,
inputFormatters: inputFormatters,
onChanged: onChanged,
autofillHints: autofillHints,
maxLines: maxLines,
2023-09-08 11:50:21 +02:00
);
@override
CupertinoTextField createIosWidget(BuildContext context) =>
CupertinoTextField(
textAlign: textAlign,
controller: controller,
enabled: enabled ?? true,
2023-09-08 11:50:21 +02:00
obscureText: obscureText,
prefix: (labelText == null) ? null : Text(labelText!),
autocorrect: autocorrect,
keyboardType: keyboardType,
inputFormatters: inputFormatters,
onChanged: onChanged,
maxLines: maxLines,
2023-09-08 11:50:21 +02:00
style: textStyle,
);
}