Line data Source code
1 : import 'package:flutter/material.dart';
2 : import 'package:flutter/services.dart';
3 :
4 : class BorderedTextField extends StatelessWidget {
5 : final String hintText;
6 : final String Function(String) validator;
7 : final Function(String) onValueChanged;
8 : final TextEditingController controller;
9 : final TextInputType textInputType;
10 : final List<TextInputFormatter> inputFormatters;
11 : final bool enableSuggestions;
12 : final bool autovalidate;
13 : final bool isLoading;
14 : final TextCapitalization textCapitalization;
15 :
16 5 : const BorderedTextField({
17 : Key key,
18 : this.hintText,
19 : @required this.validator,
20 : @required this.controller,
21 : this.inputFormatters,
22 : this.textInputType,
23 : this.enableSuggestions = false,
24 : this.autovalidate = false,
25 : this.onValueChanged,
26 : this.isLoading = true,
27 : this.textCapitalization = TextCapitalization.none,
28 5 : }) : super(key: key);
29 :
30 5 : @override
31 : Widget build(BuildContext context) {
32 5 : return Stack(
33 5 : children: [
34 5 : TextFormField(
35 5 : autovalidateMode: (autovalidate)
36 : ? AutovalidateMode.onUserInteraction
37 : : AutovalidateMode.disabled,
38 5 : controller: controller,
39 5 : enableSuggestions: enableSuggestions,
40 5 : keyboardType: textInputType,
41 5 : textCapitalization: textCapitalization,
42 5 : decoration: InputDecoration(
43 5 : border: OutlineInputBorder(
44 : borderRadius: const BorderRadius.all(Radius.circular(7.0))),
45 5 : hintText: hintText,
46 :
47 : ),
48 5 : inputFormatters: inputFormatters,
49 5 : validator: validator,
50 5 : onChanged: (String newValue) {
51 5 : if (this.onValueChanged != null) {
52 6 : this.onValueChanged(newValue);
53 : }
54 : },
55 : ),
56 16 : if (isLoading && hintText == null && (controller.text == null || controller.text.length <= 0))
57 1 : Positioned(
58 : top: 25.0,
59 : left: 15,
60 1 : child: SizedBox(
61 : height: 10.0,
62 : width: 10.0,
63 1 : child: CircularProgressIndicator(
64 : strokeWidth: 2.0,
65 : ),
66 : ),
67 : )
68 : ],
69 : );
70 : }
71 : }
|