Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

107 wiersze
3.4 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:go_router/go_router.dart';
  3. import 'package:provider/provider.dart';
  4. import 'package:qadirneyriz/global_state/global_state.dart';
  5. import 'package:qadirneyriz/utils/enums/status.dart';
  6. import 'package:qadirneyriz/utils/tools/tools.dart';
  7. import 'package:qadirneyriz/widgets/custom_button.dart';
  8. import 'package:qadirneyriz/widgets/custom_textfield.dart';
  9. import 'package:flutter_gen/gen_l10n/app_localizations.dart';
  10. class AddLocationDiolog extends StatelessWidget {
  11. AddLocationDiolog({
  12. super.key,
  13. });
  14. final TextEditingController addressController = TextEditingController();
  15. @override
  16. Widget build(BuildContext context) {
  17. return Consumer<GlobalState>(
  18. builder: (context, value, child) {
  19. return Dialog(
  20. child: Padding(
  21. padding: const EdgeInsets.all(20.0),
  22. child: Column(
  23. mainAxisSize: MainAxisSize.min, // برای اندازه‌گیری درست دیالوگ
  24. children: [
  25. Text('آدرس جدید'),
  26. CustomTextField(
  27. label: 'آدرس',
  28. hintText: '',
  29. textEditingController: addressController,
  30. textInputType: TextInputType.text),
  31. SizedBox(
  32. height: 20,
  33. ),
  34. submit(value, context),
  35. ],
  36. ),
  37. ),
  38. );
  39. },
  40. );
  41. }
  42. CustomButton submit(GlobalState state, BuildContext context) {
  43. switch (state.statusAddNewAddress) {
  44. case Status.loading:
  45. return CustomButton(
  46. hieght: 40,
  47. width: double.infinity,
  48. text: AppLocalizations.of(context)!.loading,
  49. fontSize: 13,
  50. onPressed: null,
  51. topRightRadius: 10,
  52. topLeftRadius: 10,
  53. bottomLeftRadius: 10,
  54. bottomRightRadius: 10,
  55. );
  56. default:
  57. return CustomButton(
  58. hieght: 40,
  59. width: double.infinity,
  60. text: 'اظافه کردن',
  61. fontSize: 13,
  62. onPressed: () async {
  63. if (addressController.text != '') {
  64. // call add new subject
  65. final status =
  66. await state.addNewAddress(address: addressController.text);
  67. if (status == Status.ready) {
  68. // call refrresh subjects
  69. await state.getLocations(refresh: true);
  70. Tools.showCustomSnackBar(
  71. text: 'آدرس اظافه شد!',
  72. isError: false,
  73. context,
  74. );
  75. context.pop();
  76. } else {
  77. Tools.showCustomSnackBar(
  78. text: state.errorsAddNewAddress == null
  79. ? state.messageAddNewAddress ??
  80. AppLocalizations.of(context)!.haserror
  81. : Tools.combineErrorMessages(
  82. state.errorsAddNewAddress ?? {}),
  83. isError: true,
  84. context,
  85. );
  86. }
  87. } else {
  88. Tools.showCustomSnackBar(
  89. text: 'آدرس وارد کنید!',
  90. isError: true,
  91. context,
  92. );
  93. }
  94. },
  95. topRightRadius: 10,
  96. topLeftRadius: 10,
  97. bottomLeftRadius: 10,
  98. bottomRightRadius: 10,
  99. );
  100. }
  101. }
  102. }