form.dart 827 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import 'package:flutter/material.dart';
  2. class VFormCell extends StatelessWidget {
  3. final String label;
  4. final Widget child;
  5. final double? labelWidth;
  6. final bool isExpanded;
  7. const VFormCell({
  8. super.key,
  9. required this.label,
  10. required this.child,
  11. this.labelWidth,
  12. this.isExpanded = true,
  13. });
  14. @override
  15. Widget build(BuildContext context) {
  16. final body = Row(
  17. mainAxisSize: isExpanded ? MainAxisSize.max : MainAxisSize.min,
  18. children: [
  19. SizedBox(
  20. width: labelWidth ?? 100,
  21. child: Text(
  22. label,
  23. style: const TextStyle(color: Colors.black, fontSize: 16),
  24. ),
  25. ),
  26. const SizedBox(width: 4),
  27. child,
  28. ],
  29. );
  30. if (!isExpanded) return body;
  31. return Expanded(
  32. child: body,
  33. );
  34. }
  35. }