my_identity_choose_view.dart 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import '../models/index.dart';
  4. typedef MyIdentityChooseViewOnChange = Function(String identityDn);
  5. class MyIdentityChooseView extends StatefulWidget {
  6. const MyIdentityChooseView({super.key, required this.identityList, this.onChange});
  7. final List<O2Identity> identityList;
  8. final MyIdentityChooseViewOnChange? onChange;
  9. @override
  10. State<MyIdentityChooseView> createState() => _MyIdentityChooseViewState();
  11. }
  12. class _MyIdentityChooseViewState extends State<MyIdentityChooseView> {
  13. String selectIdentityDn = '';
  14. @override
  15. Widget build(BuildContext context) {
  16. List<Widget> all = topTitle();
  17. all.addAll(identityViewList());
  18. return Column(
  19. crossAxisAlignment: CrossAxisAlignment.start,
  20. children: all,
  21. );
  22. }
  23. void clickIdentity(O2Identity id) {
  24. setState(() {
  25. selectIdentityDn = id.distinguishedName ?? '';
  26. if (widget.onChange != null) {
  27. widget.onChange!(selectIdentityDn);
  28. }
  29. });
  30. }
  31. List<Widget> topTitle() {
  32. return [
  33. Text('contact_picker_identity_title'.tr, style: Theme.of(context).textTheme.bodyLarge),
  34. const SizedBox(height: 10)
  35. ];
  36. }
  37. List<Widget> identityViewList() {
  38. if (selectIdentityDn.isEmpty && widget.identityList.isNotEmpty) {
  39. selectIdentityDn = widget.identityList[0].distinguishedName ?? '';
  40. if (widget.onChange != null) {
  41. widget.onChange!(selectIdentityDn);
  42. }
  43. }
  44. return widget.identityList.map((element) {
  45. final dutyList = element.woUnitDutyList ?? [];
  46. final duty = dutyList.map((e) => e.name ?? '').join(',');
  47. return InkWell(
  48. onTap: () => clickIdentity(element),
  49. child: cardBox(
  50. context,
  51. element.distinguishedName == selectIdentityDn,
  52. Column(
  53. crossAxisAlignment: CrossAxisAlignment.center,
  54. children: [
  55. const SizedBox(height: 5),
  56. Row(
  57. children: [
  58. Expanded(
  59. flex: 1,
  60. child: Text(element.name ?? '',
  61. style: Theme.of(context).textTheme.bodyMedium,
  62. textAlign: TextAlign.start)),
  63. Expanded(
  64. flex: 1,
  65. child: Text('【${element.unitName}】',
  66. style: Theme.of(context).textTheme.bodyMedium,
  67. textAlign: TextAlign.end))
  68. ],
  69. ),
  70. const SizedBox(height: 5),
  71. Row(
  72. children: [
  73. Text(
  74. 'contact_picker_identity_org_title'.tr,
  75. style: Theme.of(context)
  76. .textTheme
  77. .bodyLarge
  78. ?.copyWith(fontWeight: FontWeight.bold),
  79. ),
  80. const SizedBox(width: 10),
  81. Expanded(
  82. flex: 1,
  83. child: Text('${element.unitLevelName}',
  84. style: Theme.of(context).textTheme.bodyMedium)
  85. )
  86. ],
  87. ),
  88. const SizedBox(height: 5),
  89. Row(
  90. children: [
  91. Text(
  92. 'contact_picker_identity_duty_title'.tr,
  93. style: Theme.of(context)
  94. .textTheme
  95. .bodyLarge
  96. ?.copyWith(fontWeight: FontWeight.bold),
  97. ),
  98. const SizedBox(width: 10),
  99. Expanded(
  100. flex: 1,
  101. child: Text(duty,
  102. style: Theme.of(context).textTheme.bodyMedium))
  103. ],
  104. ),
  105. ],
  106. )));
  107. }).toList();
  108. }
  109. Widget cardBox(BuildContext context, bool isSelected, Widget child) {
  110. return Card(
  111. margin: const EdgeInsets.only(bottom: 10, left: 15, right: 15),
  112. shape: RoundedRectangleBorder(
  113. side: isSelected
  114. ? BorderSide(color: Theme.of(context).colorScheme.primary)
  115. : BorderSide.none,
  116. borderRadius: const BorderRadius.all(Radius.circular(10))),
  117. child: Padding(padding: const EdgeInsets.all(10), child: child));
  118. }
  119. }