1import 'package:flutter/material.dart';
2
3class PlainTextField extends StatelessWidget {
4 final String label;
5 final TextEditingController controller;
6 final int maxLines;
7 final bool enabled;
8 final TextInputType? keyboardType;
9 final String? hintText;
10 final void Function(String)? onChanged;
11 final Widget? prefixIcon;
12 final Widget? suffixIcon;
13
14 const PlainTextField({
15 super.key,
16 required this.label,
17 required this.controller,
18 this.maxLines = 1,
19 this.enabled = true,
20 this.keyboardType,
21 this.hintText,
22 this.onChanged,
23 this.prefixIcon,
24 this.suffixIcon,
25 });
26
27 @override
28 Widget build(BuildContext context) {
29 final theme = Theme.of(context);
30 return Column(
31 crossAxisAlignment: CrossAxisAlignment.start,
32 children: [
33 Text(
34 label,
35 style: theme.textTheme.bodyMedium?.copyWith(
36 fontWeight: FontWeight.w500,
37 color: theme.colorScheme.onSurface,
38 ),
39 ),
40 const SizedBox(height: 6),
41 Container(
42 decoration: BoxDecoration(
43 color: theme.brightness == Brightness.dark ? Colors.grey[850] : Colors.grey[300],
44 borderRadius: BorderRadius.circular(8),
45 ),
46 child: Focus(
47 child: Builder(
48 builder: (context) {
49 final isFocused = Focus.of(context).hasFocus;
50 return Stack(
51 children: [
52 TextField(
53 controller: controller,
54 maxLines: maxLines,
55 enabled: enabled,
56 keyboardType: keyboardType,
57 onChanged: onChanged,
58 style: theme.textTheme.bodyMedium?.copyWith(fontSize: 15),
59 decoration: InputDecoration(
60 hintText: hintText,
61 hintStyle: theme.textTheme.bodyMedium?.copyWith(color: theme.hintColor),
62 border: InputBorder.none,
63 contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
64 isDense: true,
65 prefixIcon: prefixIcon,
66 suffixIcon: suffixIcon,
67 ),
68 ),
69 // Border overlay
70 Positioned.fill(
71 child: IgnorePointer(
72 child: AnimatedContainer(
73 duration: const Duration(milliseconds: 150),
74 decoration: BoxDecoration(
75 border: Border.all(
76 color: isFocused ? theme.colorScheme.primary : theme.dividerColor,
77 width: isFocused ? 2 : 0,
78 ),
79 borderRadius: BorderRadius.circular(8),
80 ),
81 ),
82 ),
83 ),
84 ],
85 );
86 },
87 ),
88 ),
89 ),
90 ],
91 );
92 }
93}