LibAC-flutter/lib/TextFields.dart

75 lines
1.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
enum InputType {
Text,
Number,
Date;
TextInputType getType() {
switch (this) {
case Text:
return TextInputType.text;
case Number:
return TextInputType.number;
case Date:
return TextInputType.datetime;
}
}
List<TextInputFormatter> getFormatters() {
var lst = [];
switch (this) {
case Text:
return [FilteringTextInputFormatter.deny("")];
case Number:
return [FilteringTextInputFormatter.digitsOnly];
case Date:
return [
FilteringTextInputFormatter.digitsOnly,
FilteringTextInputFormatter.allow("-"),
FilteringTextInputFormatter.allow("/")
];
}
}
}
class HighlightTextfield extends StatelessWidget {
TextEditingController controller;
InputType inputStyle;
Color selected;
Color inactive;
HighlightTextfield(
{required this.controller,
required this.inputStyle,
required this.selected,
required this.inactive});
@override
Widget build(BuildContext context) {
return TextField(
controller: controller,
keyboardType: inputStyle.getType(),
inputFormatters: inputStyle.getFormatters(),
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: selected,
),
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: inactive,
),
),
),
);
}
void updateColors(Color active, Color inactive) {
selected = active;
this.inactive = inactive;
}
}