78 lines
2.2 KiB
Dart
78 lines
2.2 KiB
Dart
// ignore_for_file: use_key_in_widget_constructors
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
enum ReusableWidgetType {
|
|
textField,
|
|
textView,
|
|
elevatedButton,
|
|
}
|
|
|
|
class ReusableTextWidget extends StatelessWidget {
|
|
final TextEditingController? controller;
|
|
final String? hintText;
|
|
final VoidCallback? onPressed;
|
|
final ReusableWidgetType widgetType;
|
|
final Icon? icon;
|
|
final ValueChanged<String>? onTextChanged; // Callback for text changes
|
|
|
|
// ignore: prefer_const_constructors_in_immutables
|
|
ReusableTextWidget(
|
|
{this.controller,
|
|
this.hintText,
|
|
required this.widgetType,
|
|
this.onPressed,
|
|
this.icon,
|
|
this.onTextChanged});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
switch (widgetType) {
|
|
case ReusableWidgetType.textField:
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: TextField(
|
|
controller: controller,
|
|
decoration: InputDecoration(
|
|
contentPadding: const EdgeInsets.symmetric(vertical: 9.0),
|
|
border: const OutlineInputBorder(),
|
|
hintText: hintText,
|
|
prefixIcon: icon,
|
|
),
|
|
),
|
|
);
|
|
case ReusableWidgetType.textView:
|
|
return Text(
|
|
hintText!,
|
|
style: const TextStyle(fontSize: 16, color: Colors.blueAccent),
|
|
);
|
|
|
|
case ReusableWidgetType.elevatedButton:
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 18.0),
|
|
child: FractionallySizedBox(
|
|
widthFactor: 0.9,
|
|
child: ElevatedButton(
|
|
onPressed: () {},
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.blue,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.only(
|
|
topRight: Radius.circular(0.0),
|
|
topLeft: Radius.circular(0.0),
|
|
),
|
|
),
|
|
),
|
|
child: Text(
|
|
hintText!,
|
|
style: const TextStyle(color: Colors.white),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
default:
|
|
return const SizedBox.shrink();
|
|
}
|
|
}
|
|
}
|