-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrequency.dart
119 lines (111 loc) · 3.98 KB
/
frequency.dart
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
import 'package:flutter/material.dart';
import 'payment.dart'; // Import payment.dart
void main() => runApp(GreenTrayApp() as Widget);
class GreenTrayApp {
}
class FrequencyPage extends StatefulWidget {
const FrequencyPage({Key? key}) : super(key: key);
@override
_FrequencyPageState createState() => _FrequencyPageState();
}
class _FrequencyPageState extends State<FrequencyPage> {
String selectedFrequency = 'None'; // Default selection is now 'None'
DateTime? selectedDate; // To hold selected date
// List of frequency options with 'None' as the default option
final List<String> frequencyOptions = ['None', 'Daily', 'Weekly', 'Monthly', 'Yearly', 'Custom Date'];
// Function to pick a date from calendar
Future<void> _selectDate(BuildContext context) async {
final DateTime? pickedDate = await showDatePicker(
context: context,
initialDate: DateTime.now(), // Default today's date
firstDate: DateTime.now(), // Starting today
lastDate: DateTime(2101), // Future limit
);
if (pickedDate != null && pickedDate != selectedDate) {
setState(() {
selectedDate = pickedDate;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Select Delivery Frequency'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Select Frequency:',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
DropdownButton<String>(
value: selectedFrequency,
items: frequencyOptions.map((String frequency) {
return DropdownMenuItem<String>(
value: frequency,
child: Text(frequency),
);
}).toList(),
onChanged: (String? newValue) {
setState(() {
selectedFrequency = newValue!;
if (selectedFrequency != 'Custom Date') {
selectedDate = null; // Reset date if not Custom Date
}
});
},
),
const SizedBox(height: 20),
if (selectedFrequency == 'Custom Date') ...[
const Text(
'Select Delivery Date:',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
TextButton(
onPressed: () => _selectDate(context),
child: const Text(
'Choose Date',
style: TextStyle(fontSize: 16),
),
),
selectedDate != null
? Text(
"Selected date: ${selectedDate!.toLocal()}".split(' ')[0],
style: const TextStyle(fontSize: 16),
)
: const Text(
'No date selected',
style: TextStyle(fontSize: 16),
),
],
const Spacer(),
ElevatedButton(
onPressed: () {
// Ensure a frequency is selected (excluding 'None')
if (selectedFrequency != 'None' &&
(selectedFrequency != 'Custom Date' || selectedDate != null)) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => PaymentPage()),
);
} else {
// Show alert if no frequency or date is selected
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Please select a delivery frequency'),
),
);
}
},
child: const Text('Confirm'),
),
],
),
),
);
}
}