-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisable_zipcode_autocomplete_example.dart
More file actions
158 lines (143 loc) · 5.52 KB
/
Copy pathdisable_zipcode_autocomplete_example.dart
File metadata and controls
158 lines (143 loc) · 5.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import 'package:flutter/material.dart';
import 'package:thai_address_picker/thai_address_picker.dart';
/// Example: Disable Zip Code Autocomplete
///
/// This example demonstrates how to disable zip code autocomplete feature.
/// Useful when you want a simple text field for zip code input without
/// the autocomplete suggestions dropdown.
void main() {
runApp(const MaterialApp(home: DisableZipCodeAutocompleteExample(), debugShowCheckedModeBanner: false));
}
class DisableZipCodeAutocompleteExample extends StatefulWidget {
const DisableZipCodeAutocompleteExample({super.key});
@override
State<DisableZipCodeAutocompleteExample> createState() => _DisableZipCodeAutocompleteExampleState();
}
class _DisableZipCodeAutocompleteExampleState extends State<DisableZipCodeAutocompleteExample> {
final _repository = ThaiAddressRepository();
late ThaiAddressController _controller;
ThaiAddress? _selectedAddress;
bool _isLoading = true;
@override
void initState() {
super.initState();
_controller = ThaiAddressController(repository: _repository);
_init();
}
Future<void> _init() async {
await _repository.initialize();
if (mounted) setState(() => _isLoading = false);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (_isLoading) {
return Scaffold(
appBar: AppBar(title: const Text('ปิด Zip Code Autocomplete'), backgroundColor: Colors.blue, foregroundColor: Colors.white),
body: const Center(child: CircularProgressIndicator()),
);
}
return Scaffold(
appBar: AppBar(title: const Text('ปิด Zip Code Autocomplete'), backgroundColor: Colors.blue, foregroundColor: Colors.white),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Info Card
Card(
color: Colors.blue.shade50,
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.info_outline, color: Colors.blue.shade700),
const SizedBox(width: 8),
Text(
'ตัวอย่างการปิด Autocomplete',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.blue.shade700),
),
],
),
const SizedBox(height: 8),
const Text(
'ใช้ showZipCodeAutocomplete: false\n'
'เพื่อแสดง TextField ธรรมดาแทน Autocomplete\n'
'เหมาะสำหรับกรณีที่ไม่ต้องการ suggestions',
style: TextStyle(fontSize: 14),
),
],
),
),
),
const SizedBox(height: 20),
// Form with disabled autocomplete
const Text('ฟอร์มที่อยู่ (ไม่มี Autocomplete)', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 16),
ThaiAddressForm(
controller: _controller,
// ปิด Zip Code Autocomplete
showZipCodeAutocomplete: false,
onChanged: (address) {
setState(() {
_selectedAddress = address;
});
},
),
const SizedBox(height: 24),
// Display selected address
if (_selectedAddress != null) ...[
const Divider(),
const SizedBox(height: 16),
const Text('ที่อยู่ที่เลือก:', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 12),
_buildAddressCard(_selectedAddress!),
],
],
),
),
);
}
Widget _buildAddressCard(ThaiAddress address) {
return Card(
elevation: 2,
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (address.provinceTh != null) _buildInfoRow('จังหวัด', address.provinceTh!),
if (address.districtTh != null) _buildInfoRow('อำเภอ/เขต', address.districtTh!),
if (address.subDistrictTh != null) _buildInfoRow('ตำบล/แขวง', address.subDistrictTh!),
if (address.zipCode != null) _buildInfoRow('รหัสไปรษณีย์', address.zipCode!),
],
),
),
);
}
Widget _buildInfoRow(String label, String value) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 120,
child: Text(
'$label:',
style: const TextStyle(fontWeight: FontWeight.bold, color: Colors.grey),
),
),
Expanded(child: Text(value, style: const TextStyle(fontSize: 16))),
],
),
);
}
}