如何组合这些小部件以使该行正确显示?

huangapple go评论85阅读模式
英文:

How do I compose these widgets to get this row to display correctly?

问题

我正在处理一个表单,尝试在屏幕上布置组件。要收集的每个数据均由位于空的轮廓表单字段上方的左对齐标签表示。这些都位于一个列内,位于一个单一的单一子滚动视图内,位于一个安全区内。

我有一对数据点,我想将它们放在一行上,左侧项目是位于部分宽度表单字段上方的左对齐标签,右侧项目是右对齐开关,其左侧有一个标签。

我可以使所有组件都显示在一行上,但我无法使左对齐的标签起作用,无法使标签/开关组合垂直对齐到文本字段的中心,并且无法使标签/开关组合右对齐。下面的图像是我卡住的地方;这是让我到达那里的代码。

我在这里缺少什么?我感觉这是一些简单的东西,但我似乎无法弄清楚。

英文:

I am working on a form and trying to lay out the components on-screen. Each piece of data to be collected is represented by a left-aligned label above an empty, outlined form field. These are all inside a column, inside a singlechildscrollview, inside a safearea.

I have one pair of data points I'd like to put on a single row, such that the left item is a left-aligned label above a partial-width form field, and the right item is a right-aligned switch with a label to the left.

I can get all the components to appear on a single row, but I can't get the left-aligned label to work, I can't get the label/switch combo to vertically align to the center of the textfield, and I can't get the label/switch combo to be right-aligned. The image below is where I'm stuck; here's the code that got me there.

What am I missing here? I feel like it's something simple but I can't seem to figure it out.

  1. //* AMOUNT & DEPOSIT
  2. Row(
  3. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  4. children: [
  5. Expanded(
  6. child: Column(
  7. mainAxisAlignment: MainAxisAlignment.start,
  8. children: [
  9. Text('Amount'.hardcoded, style: labelStyle),
  10. vgap(5),
  11. TextFormField(
  12. keyboardType: const TextInputType.numberWithOptions(
  13. decimal: true),
  14. autofocus: true,
  15. decoration: const InputDecoration(
  16. contentPadding: EdgeInsets.fromLTRB(16, 4, 0, 4),
  17. border: OutlineInputBorder(
  18. borderSide: BorderSide(),
  19. ),
  20. focusedBorder: OutlineInputBorder(
  21. borderSide: BorderSide(
  22. color: Colors.black,
  23. ),
  24. ),
  25. ),
  26. style: const TextStyle(
  27. fontWeight: FontWeight.bold,
  28. color: Colors.black38,
  29. ),
  30. ),
  31. ],
  32. ),
  33. ),
  34. Expanded(
  35. child: Row(
  36. crossAxisAlignment: CrossAxisAlignment.center,
  37. children: [
  38. Text('Deposit'.hardcoded, style: labelStyle),
  39. hgap(5),
  40. Switch.adaptive(
  41. value: isDeposit,
  42. onChanged: (value) =>
  43. setState(() => isDeposit = value),
  44. ),
  45. ],
  46. ),
  47. ),
  48. ],
  49. ),

如何组合这些小部件以使该行正确显示?

答案1

得分: 1

这是你要翻译的部分:

  1. Column(
  2. crossAxisAlignment: CrossAxisAlignment.start,
  3. children: [
  4. Text('Amount',style: Theme.of(context).textTheme.titleMedium,),
  5. Row(
  6. children: [
  7. Expanded(
  8. child: TextFormField(
  9. keyboardType: const TextInputType.numberWithOptions(
  10. decimal: true),
  11. autofocus: true,
  12. decoration: const InputDecoration(
  13. contentPadding: EdgeInsets.fromLTRB(16, 4, 0, 4),
  14. border: OutlineInputBorder(
  15. borderSide: BorderSide(),
  16. ),
  17. focusedBorder: OutlineInputBorder(
  18. borderSide: BorderSide(
  19. color: Colors.black,
  20. ),
  21. ),
  22. ),
  23. style: const TextStyle(
  24. fontWeight: FontWeight.bold,
  25. color: Colors.black38,
  26. ),
  27. ),
  28. ),
  29. const SizedBox(width: 20,),
  30. Text('Deposit',style: Theme.of(context).textTheme.titleMedium,),
  31. const SizedBox(width: 5,),
  32. Switch.adaptive(
  33. value: true,
  34. onChanged: (value){},
  35. ),
  36. ],
  37. ),
  38. ],
  39. )

请注意,我已经将其中的HTML实体字符(如''')还原为正常的单引号。

英文:

is this what you trying to do?

如何组合这些小部件以使该行正确显示?

  1. Column(
  2. crossAxisAlignment: CrossAxisAlignment.start,
  3. children: [
  4. Text('Amount',style: Theme.of(context).textTheme.titleMedium,),
  5. Row(
  6. children: [
  7. Expanded(
  8. child: TextFormField(
  9. keyboardType: const TextInputType.numberWithOptions(
  10. decimal: true),
  11. autofocus: true,
  12. decoration: const InputDecoration(
  13. contentPadding: EdgeInsets.fromLTRB(16, 4, 0, 4),
  14. border: OutlineInputBorder(
  15. borderSide: BorderSide(),
  16. ),
  17. focusedBorder: OutlineInputBorder(
  18. borderSide: BorderSide(
  19. color: Colors.black,
  20. ),
  21. ),
  22. ),
  23. style: const TextStyle(
  24. fontWeight: FontWeight.bold,
  25. color: Colors.black38,
  26. ),
  27. ),
  28. ),
  29. const SizedBox(width: 20,),
  30. Text('Deposit',style: Theme.of(context).textTheme.titleMedium,),
  31. const SizedBox(width: 5,),
  32. Switch.adaptive(
  33. value: true,
  34. onChanged: (value){},
  35. ),
  36. ],
  37. ),
  38. ],
  39. ),

huangapple
  • 本文由 发表于 2023年5月7日 14:14:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76192448.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定