creek

The AI Image Editor of 2030

lib/ui/widgets/text_field.dart (2299B)


 1import 'package:flutter/material.dart';
 2import 'package:creekui/ui/styles/variables.dart';
 3
 4class CommonTextField extends StatelessWidget {
 5  final String? label;
 6  final String hintText;
 7  final TextEditingController controller;
 8  final int maxLines;
 9  final bool isRequired;
10  final ValueChanged<String>? onSubmitted;
11  final ValueChanged<String>? onChanged;
12  final Widget? suffixIcon;
13  final bool autoFocus;
14
15  const CommonTextField({
16    super.key,
17    this.label,
18    required this.hintText,
19    required this.controller,
20    this.maxLines = 1,
21    this.isRequired = false,
22    this.onSubmitted,
23    this.onChanged,
24    this.suffixIcon,
25    this.autoFocus = false,
26  });
27
28  @override
29  Widget build(BuildContext context) {
30    return Column(
31      crossAxisAlignment: CrossAxisAlignment.start,
32      children: [
33        if (label != null) ...[
34          Row(
35            children: [
36              Text(
37                label!,
38                style: Variables.bodyStyle.copyWith(
39                  fontWeight: FontWeight.w500,
40                ),
41              ),
42              if (isRequired)
43                Text(
44                  '*',
45                  style: Variables.bodyStyle.copyWith(
46                    color: const Color(0xFF4F39F6),
47                    fontSize: 12,
48                  ),
49                ),
50            ],
51          ),
52          const SizedBox(height: 6),
53        ],
54        Container(
55          decoration: BoxDecoration(
56            color: Variables.borderSubtle,
57            borderRadius: BorderRadius.circular(Variables.radiusSmall),
58          ),
59          child: TextField(
60            controller: controller,
61            maxLines: maxLines,
62            autofocus: autoFocus,
63            onSubmitted: onSubmitted,
64            onChanged: onChanged,
65            style: Variables.bodyStyle,
66            decoration: InputDecoration(
67              hintText: hintText,
68              hintStyle: Variables.bodyStyle.copyWith(
69                color: Variables.textSecondary,
70              ),
71              border: InputBorder.none,
72              contentPadding: const EdgeInsets.symmetric(
73                horizontal: 16,
74                vertical: 12,
75              ),
76              suffixIcon: suffixIcon,
77            ),
78          ),
79        ),
80      ],
81    );
82  }
83}