|
|
|
|
@ -25,6 +25,14 @@ class _EnvironmentConfigSheetState extends State<EnvironmentConfigSheet> {
|
|
|
|
|
|
|
|
|
|
AppEnvironmentPreset? _selectedPreset;
|
|
|
|
|
bool _isSaving = false;
|
|
|
|
|
bool _isCustomMode = false;
|
|
|
|
|
|
|
|
|
|
// Controllers for custom URL inputs
|
|
|
|
|
final _baseUrlController = TextEditingController();
|
|
|
|
|
final _rcBaseUrlController = TextEditingController();
|
|
|
|
|
final _pharmacyBaseUrlController = TextEditingController();
|
|
|
|
|
final _exaCartBaseUrlController = TextEditingController();
|
|
|
|
|
String _selectedPayfortMode = 'production';
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
@ -32,24 +40,80 @@ class _EnvironmentConfigSheetState extends State<EnvironmentConfigSheet> {
|
|
|
|
|
_loadCurrent();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_baseUrlController.dispose();
|
|
|
|
|
_rcBaseUrlController.dispose();
|
|
|
|
|
_pharmacyBaseUrlController.dispose();
|
|
|
|
|
_exaCartBaseUrlController.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _loadCurrent() async {
|
|
|
|
|
final preset = await _envService.getCurrentPreset();
|
|
|
|
|
final currentBaseUrl = await _envService.getCurrentBaseUrl();
|
|
|
|
|
final currentRcUrl = await _envService.getCurrentRcUrl();
|
|
|
|
|
final currentPharmacyUrl = await _envService.getCurrentPharmacyUrl();
|
|
|
|
|
final currentExaCartUrl = await _envService.getCurrentExaCartUrl();
|
|
|
|
|
final currentPayfortMode = await _envService.getCurrentPayfortMode();
|
|
|
|
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
setState(() {
|
|
|
|
|
// If no preset is stored, fall back to production (first preset)
|
|
|
|
|
_selectedPreset = preset ?? kEnvironmentPresets.first;
|
|
|
|
|
|
|
|
|
|
// Load current values into text controllers
|
|
|
|
|
_baseUrlController.text = currentBaseUrl;
|
|
|
|
|
_rcBaseUrlController.text = currentRcUrl;
|
|
|
|
|
_pharmacyBaseUrlController.text = currentPharmacyUrl;
|
|
|
|
|
_exaCartBaseUrlController.text = currentExaCartUrl;
|
|
|
|
|
_selectedPayfortMode = currentPayfortMode;
|
|
|
|
|
|
|
|
|
|
// Check if current config is custom (not matching any preset)
|
|
|
|
|
_isCustomMode = preset == null;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _selectPreset(AppEnvironmentPreset p) {
|
|
|
|
|
setState(() => _selectedPreset = p);
|
|
|
|
|
setState(() {
|
|
|
|
|
_selectedPreset = p;
|
|
|
|
|
_isCustomMode = false;
|
|
|
|
|
// Update text fields with preset values
|
|
|
|
|
_baseUrlController.text = p.baseUrl;
|
|
|
|
|
_rcBaseUrlController.text = p.rcBaseUrl;
|
|
|
|
|
_pharmacyBaseUrlController.text = p.pharmacyBaseUrl;
|
|
|
|
|
_exaCartBaseUrlController.text = p.exaCartBaseUrl;
|
|
|
|
|
_selectedPayfortMode = p.payfortMode;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _enableCustomMode() {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isCustomMode = true;
|
|
|
|
|
_selectedPreset = null;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _save() async {
|
|
|
|
|
if (_selectedPreset == null) return;
|
|
|
|
|
setState(() => _isSaving = true);
|
|
|
|
|
try {
|
|
|
|
|
await _envService.applyPreset(_selectedPreset!);
|
|
|
|
|
if (_isCustomMode) {
|
|
|
|
|
// Save custom URLs directly
|
|
|
|
|
await _envService.applyCustomEnvironment(
|
|
|
|
|
baseUrl: _baseUrlController.text.trim(),
|
|
|
|
|
rcBaseUrl: _rcBaseUrlController.text.trim(),
|
|
|
|
|
pharmacyBaseUrl: _pharmacyBaseUrlController.text.trim(),
|
|
|
|
|
exaCartBaseUrl: _exaCartBaseUrlController.text.trim(),
|
|
|
|
|
payfortMode: _selectedPayfortMode,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
// Save preset
|
|
|
|
|
if (_selectedPreset == null) {
|
|
|
|
|
setState(() => _isSaving = false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await _envService.applyPreset(_selectedPreset!);
|
|
|
|
|
}
|
|
|
|
|
if (mounted) Navigator.of(context).pop(true);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
setState(() => _isSaving = false);
|
|
|
|
|
@ -73,7 +137,6 @@ class _EnvironmentConfigSheetState extends State<EnvironmentConfigSheet> {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final mq = MediaQuery.of(context);
|
|
|
|
|
final p = _selectedPreset;
|
|
|
|
|
return Container(
|
|
|
|
|
height: mq.size.height * 0.85,
|
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
|
@ -126,32 +189,89 @@ class _EnvironmentConfigSheetState extends State<EnvironmentConfigSheet> {
|
|
|
|
|
Wrap(
|
|
|
|
|
spacing: 8,
|
|
|
|
|
runSpacing: 8,
|
|
|
|
|
children: kEnvironmentPresets
|
|
|
|
|
.map((preset) => _Chip(
|
|
|
|
|
label: preset.label,
|
|
|
|
|
selected: _selectedPreset?.label == preset.label,
|
|
|
|
|
onTap: () => _selectPreset(preset),
|
|
|
|
|
))
|
|
|
|
|
.toList(),
|
|
|
|
|
children: [
|
|
|
|
|
...kEnvironmentPresets
|
|
|
|
|
.map((preset) => _Chip(
|
|
|
|
|
label: preset.label,
|
|
|
|
|
selected: !_isCustomMode && _selectedPreset?.label == preset.label,
|
|
|
|
|
onTap: () => _selectPreset(preset),
|
|
|
|
|
))
|
|
|
|
|
.toList(),
|
|
|
|
|
_Chip(
|
|
|
|
|
label: 'Custom',
|
|
|
|
|
selected: _isCustomMode,
|
|
|
|
|
onTap: _enableCustomMode,
|
|
|
|
|
isCustom: true,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
|
|
|
|
|
// ── URL preview (read-only) ────────────────────────────
|
|
|
|
|
if (p != null) ...[
|
|
|
|
|
const _SectionLabel('URLs for selected environment'),
|
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
_UrlDisplay(label: 'Main Base URL', value: p.baseUrl),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
_UrlDisplay(label: 'RC Base URL', value: p.rcBaseUrl),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
_UrlDisplay(label: 'Pharmacy Base URL', value: p.pharmacyBaseUrl),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
_UrlDisplay(label: 'ExaCart (Offers) URL', value: p.exaCartBaseUrl),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
_UrlDisplay(label: 'PayFort Mode', value: p.payfortMode),
|
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
],
|
|
|
|
|
// ── URL configuration (editable in custom mode) ────────────────────────────
|
|
|
|
|
const _SectionLabel('Environment URLs'),
|
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
_UrlTextField(
|
|
|
|
|
label: 'Main Base URL',
|
|
|
|
|
controller: _baseUrlController,
|
|
|
|
|
enabled: _isCustomMode,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
_UrlTextField(
|
|
|
|
|
label: 'RC Base URL',
|
|
|
|
|
controller: _rcBaseUrlController,
|
|
|
|
|
enabled: _isCustomMode,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
_UrlTextField(
|
|
|
|
|
label: 'Pharmacy Base URL',
|
|
|
|
|
controller: _pharmacyBaseUrlController,
|
|
|
|
|
enabled: _isCustomMode,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
_UrlTextField(
|
|
|
|
|
label: 'ExaCart (Offers) URL',
|
|
|
|
|
controller: _exaCartBaseUrlController,
|
|
|
|
|
enabled: _isCustomMode,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
|
|
|
|
|
|
// PayFort Mode selector
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
const Text('PayFort Mode',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: Colors.grey)),
|
|
|
|
|
const SizedBox(height: 6),
|
|
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: _RadioOption(
|
|
|
|
|
label: 'Production',
|
|
|
|
|
value: 'production',
|
|
|
|
|
groupValue: _selectedPayfortMode,
|
|
|
|
|
enabled: _isCustomMode,
|
|
|
|
|
onChanged: (val) => setState(() => _selectedPayfortMode = val!),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: _RadioOption(
|
|
|
|
|
label: 'Sandbox',
|
|
|
|
|
value: 'sandbox',
|
|
|
|
|
groupValue: _selectedPayfortMode,
|
|
|
|
|
enabled: _isCustomMode,
|
|
|
|
|
onChanged: (val) => setState(() => _selectedPayfortMode = val!),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 24),
|
|
|
|
|
|
|
|
|
|
// ── Reset to Default ──────────────────────────────────
|
|
|
|
|
InkWell(
|
|
|
|
|
@ -281,8 +401,9 @@ class _Chip extends StatelessWidget {
|
|
|
|
|
final String label;
|
|
|
|
|
final bool selected;
|
|
|
|
|
final VoidCallback onTap;
|
|
|
|
|
final bool isCustom;
|
|
|
|
|
const _Chip(
|
|
|
|
|
{required this.label, required this.selected, required this.onTap});
|
|
|
|
|
{required this.label, required this.selected, required this.onTap, this.isCustom = false});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
@ -292,28 +413,44 @@ class _Chip extends StatelessWidget {
|
|
|
|
|
duration: const Duration(milliseconds: 200),
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: selected ? const Color(0xFF2B353E) : Colors.white,
|
|
|
|
|
color: selected
|
|
|
|
|
? (isCustom ? const Color(0xFF6C5CE7) : const Color(0xFF2B353E))
|
|
|
|
|
: Colors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: selected
|
|
|
|
|
? const Color(0xFF2B353E)
|
|
|
|
|
? (isCustom ? const Color(0xFF6C5CE7) : const Color(0xFF2B353E))
|
|
|
|
|
: Colors.grey.shade300,
|
|
|
|
|
width: selected ? 2 : 1),
|
|
|
|
|
),
|
|
|
|
|
child: Text(label,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: selected ? Colors.white : Colors.black87)),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
if (isCustom && selected) ...[
|
|
|
|
|
const Icon(Icons.edit, size: 14, color: Colors.white),
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
],
|
|
|
|
|
Text(label,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: selected ? Colors.white : Colors.black87)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _UrlDisplay extends StatelessWidget {
|
|
|
|
|
class _UrlTextField extends StatelessWidget {
|
|
|
|
|
final String label;
|
|
|
|
|
final String value;
|
|
|
|
|
const _UrlDisplay({required this.label, required this.value});
|
|
|
|
|
final TextEditingController controller;
|
|
|
|
|
final bool enabled;
|
|
|
|
|
const _UrlTextField({
|
|
|
|
|
required this.label,
|
|
|
|
|
required this.controller,
|
|
|
|
|
required this.enabled,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
@ -325,25 +462,111 @@ class _UrlDisplay extends StatelessWidget {
|
|
|
|
|
fontSize: 11,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
color: Colors.grey)),
|
|
|
|
|
const SizedBox(height: 3),
|
|
|
|
|
Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(horizontal: 12, vertical: 9),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.grey.shade100,
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
border: Border.all(color: Colors.grey.shade200),
|
|
|
|
|
const SizedBox(height: 6),
|
|
|
|
|
TextField(
|
|
|
|
|
controller: controller,
|
|
|
|
|
enabled: enabled,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
color: enabled ? const Color(0xFF2B353E) : Colors.grey.shade600),
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
filled: true,
|
|
|
|
|
fillColor: enabled ? Colors.white : Colors.grey.shade100,
|
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
|
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
borderSide: BorderSide(color: Colors.grey.shade300),
|
|
|
|
|
),
|
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
borderSide: BorderSide(color: Colors.grey.shade300),
|
|
|
|
|
),
|
|
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
borderSide: const BorderSide(color: Color(0xFF6C5CE7), width: 2),
|
|
|
|
|
),
|
|
|
|
|
disabledBorder: OutlineInputBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
borderSide: BorderSide(color: Colors.grey.shade200),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Text(value,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 12, color: Color(0xFF2B353E))),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _RadioOption extends StatelessWidget {
|
|
|
|
|
final String label;
|
|
|
|
|
final String value;
|
|
|
|
|
final String groupValue;
|
|
|
|
|
final bool enabled;
|
|
|
|
|
final Function(String?) onChanged;
|
|
|
|
|
|
|
|
|
|
const _RadioOption({
|
|
|
|
|
required this.label,
|
|
|
|
|
required this.value,
|
|
|
|
|
required this.groupValue,
|
|
|
|
|
required this.enabled,
|
|
|
|
|
required this.onChanged,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final isSelected = value == groupValue;
|
|
|
|
|
return GestureDetector(
|
|
|
|
|
onTap: enabled ? () => onChanged(value) : null,
|
|
|
|
|
child: Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: enabled
|
|
|
|
|
? (isSelected ? const Color(0xFF6C5CE7).withAlpha(25) : Colors.white)
|
|
|
|
|
: Colors.grey.shade100,
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: enabled
|
|
|
|
|
? (isSelected ? const Color(0xFF6C5CE7) : Colors.grey.shade300)
|
|
|
|
|
: Colors.grey.shade200,
|
|
|
|
|
width: isSelected ? 2 : 1,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
width: 18,
|
|
|
|
|
height: 18,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: enabled
|
|
|
|
|
? (isSelected ? const Color(0xFF6C5CE7) : Colors.grey.shade400)
|
|
|
|
|
: Colors.grey.shade300,
|
|
|
|
|
width: 2,
|
|
|
|
|
),
|
|
|
|
|
color: isSelected && enabled ? const Color(0xFF6C5CE7) : Colors.transparent,
|
|
|
|
|
),
|
|
|
|
|
child: isSelected && enabled
|
|
|
|
|
? const Icon(Icons.circle, size: 10, color: Colors.white)
|
|
|
|
|
: null,
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 8),
|
|
|
|
|
Text(
|
|
|
|
|
label,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
|
color: enabled
|
|
|
|
|
? (isSelected ? const Color(0xFF6C5CE7) : Colors.black87)
|
|
|
|
|
: Colors.grey.shade500,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|