promocode

This commit is contained in:
Dmitry 2024-08-25 01:52:11 +03:00
parent 39b91a5fb3
commit 819bdd1134
3 changed files with 187 additions and 192 deletions

View file

@ -163,165 +163,153 @@ class AddPromocodeCampaign {
}).toList(), }).toList(),
), ),
StatefulBuilder(builder: (context, setState) { StatefulBuilder(builder: (context, setState) {
return Stack( return Padding(
alignment: Alignment.center, padding: EdgeInsets.all(8.0),
children: [ child: Column(
Padding( mainAxisSize: MainAxisSize.max,
padding: EdgeInsets.all(8.0), mainAxisAlignment:
child: Column( MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max, children: [
mainAxisAlignment: Column(
MainAxisAlignment.spaceEvenly,
children: [ children: [
Column( TextParam(
children: [ 'Name',
TextParam( campaignDto.name,
'Name', (v) {
campaignDto.name, campaignDto = campaignDto.copyWith(
(v) { name: v,
campaignDto = );
campaignDto.copyWith( },
name: v, ),
TextParam(
'Template',
campaignDto.template,
(v) {
campaignDto = campaignDto.copyWith(
template: v,
);
},
description:
r'$d - digit $l - letter $s - any',
),
IntParam(
'Generation size',
campaignDto.generationSize,
(v) {
campaignDto = campaignDto.copyWith(
generationSize: v);
},
),
IntParam(
'Activations per code',
campaignDto.activationsPerCode,
(v) {
campaignDto = campaignDto.copyWith(
activationsPerCode: v,
);
},
),
DateParam(
'Start',
campaignDto.start,
(v) {
setState(() {
campaignDto = campaignDto
.copyWith(start: v);
});
},
),
DateParam(
'Finish',
campaignDto.finish,
(v) {
setState(() {
campaignDto = campaignDto
.copyWith(finish: v);
});
},
),
DateParam(
'Finish',
campaignDto.finish,
(v) {
setState(() {
campaignDto = campaignDto
.copyWith(finish: v);
});
},
),
EnumParam(
'Status',
PromoCodeCampaignStatus.values,
campaignDto.status, (v) {
setState(() {
campaignDto =
campaignDto.copyWith(status: v);
});
}),
Text(
'Created to generate promocodes\n'
'Disabled to disable\n'
'Dont use other statuses!',
style: TextStyle(fontSize: 12),
),
Text('Products:'),
ListView.builder(
shrinkWrap: true,
itemCount:
campaignDto.products.length + 1,
itemBuilder: (context, index) {
if (index ==
campaignDto.products.length) {
return ListTile(
title: Text('Add'),
onTap: () async {
final p =
await _showProductDialog(
context, null);
if (p != null) {
setState(() {
campaignDto.products
.add(p);
});
}
},
);
}
final item =
campaignDto.products[index];
return ListTile(
title: Text(
'${item.type.name} ${item.id ?? ''}'),
onTap: () async {
final p =
await _showProductDialog(
context,
item,
); );
}, if (p != null) {
), setState(() {
TextParam( campaignDto.products.add(p);
'Template', });
campaignDto.template,
(v) {
campaignDto =
campaignDto.copyWith(
template: v,
);
},
description:
r'$d - digit $l - letter $s - any',
),
IntParam(
'Generation size',
campaignDto.generationSize,
(v) {
campaignDto =
campaignDto.copyWith(
generationSize: v);
},
),
IntParam(
'Activations per code',
campaignDto.activationsPerCode,
(v) {
campaignDto =
campaignDto.copyWith(
activationsPerCode: v,
);
},
),
DateParam(
'Start',
campaignDto.start,
(v) {
setState(() {
campaignDto = campaignDto
.copyWith(start: v);
});
},
),
DateParam(
'Finish',
campaignDto.finish,
(v) {
setState(() {
campaignDto = campaignDto
.copyWith(finish: v);
});
},
),
DateParam(
'Finish',
campaignDto.finish,
(v) {
setState(() {
campaignDto = campaignDto
.copyWith(finish: v);
});
},
),
EnumParam(
'Status',
PromoCodeCampaignStatus.values,
campaignDto.status, (v) {
setState(() {
campaignDto = campaignDto
.copyWith(status: v);
});
}),
Text(
'Created to generate promocodes\n'
'Disabled to disable\n'
'Dont use other statuses!',
style: TextStyle(fontSize: 12),
),
Text('Products:'),
ListView.builder(
shrinkWrap: true,
itemCount:
campaignDto.products.length +
1,
itemBuilder: (context, index) {
if (index ==
campaignDto
.products.length) {
return ListTile(
title: Text('Add'),
onTap: () async {
final p =
await _showProductDialog(
context, null);
if (p != null) {
setState(() {
campaignDto.products
.add(p);
});
}
},
);
} }
final item =
campaignDto.products[index];
return ListTile(
title: Text(
'${item.type.name} ${item.id ?? ''}'),
onTap: () async {
final p =
await _showProductDialog(
context,
item,
);
if (p != null) {
setState(() {
campaignDto.products
.add(p);
});
}
},
trailing: IconButton(
icon: Icon(Icons.delete),
onPressed: () {
setState(() {
campaignDto.products
.remove(item);
});
},
),
);
}, },
), trailing: IconButton(
], icon: Icon(Icons.delete),
onPressed: () {
setState(() {
campaignDto.products
.remove(item);
});
},
),
);
},
), ),
], ],
), ),
), ],
], ),
); );
}), }),
], ],

View file

@ -12,54 +12,61 @@ class DateParam extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(4.0),
child: Row( child: Row(
children: [ children: [
Text(title), Text(title),
SizedBox( SizedBox(
width: 2, width: 8,
), ),
GestureDetector( Expanded(
behavior: HitTestBehavior.opaque, child: Container(
onTap: () async { padding: EdgeInsets.all(8.0),
final date = await showDatePicker( decoration: BoxDecoration(
context: context, border: Border.all(),
initialEntryMode: DatePickerEntryMode.calendar, borderRadius: BorderRadius.circular(8.0),
initialDate: initial ?? DateTime.now(), ),
firstDate: DateTime.utc(2000), child: GestureDetector(
lastDate: DateTime.utc(2050), behavior: HitTestBehavior.opaque,
).then((selectedDate) { onTap: () async {
// After selecting the date, display the time picker. final date = await showDatePicker(
if (selectedDate != null) {
return showTimePicker(
context: context, context: context,
initialTime: TimeOfDay.now(), initialEntryMode: DatePickerEntryMode.calendar,
).then((selectedTime) { initialDate: initial ?? DateTime.now(),
// Handle the selected date and time here. firstDate: DateTime.utc(2000),
if (selectedTime != null) { lastDate: DateTime.utc(2050),
DateTime selectedDateTime = DateTime( ).then((selectedDate) {
selectedDate.year, // After selecting the date, display the time picker.
selectedDate.month, if (selectedDate != null) {
selectedDate.day, return showTimePicker(
selectedTime.hour, context: context,
selectedTime.minute, initialTime: TimeOfDay.now(),
); ).then((selectedTime) {
return selectedDateTime; // Handle the selected date and time here.
if (selectedTime != null) {
DateTime selectedDateTime = DateTime(
selectedDate.year,
selectedDate.month,
selectedDate.day,
selectedTime.hour,
selectedTime.minute,
);
return selectedDateTime;
}
return null;
});
} }
return null; return null;
}); });
} onChanged(date);
return null; },
}); child: Text(
onChanged(date); initial?.let(
}, (d) =>
child: Expanded( '${d.year}.${d.month}.${d.day} ${d.hour}:${d.minute}',
child: Text( ) ??
initial?.let( 'No date',
(d) => ),
'${d.year}.${d.month}.${d.day} ${d.hour}:${d.minute}',
) ??
'No date',
), ),
), ),
), ),

View file

@ -52,7 +52,7 @@ class EnumParam<T extends Enum> extends StatelessWidget {
.toList(), .toList(),
onChanged: (v) => setState(() { onChanged: (v) => setState(() {
value = v!; value = v!;
onChanged(v!); onChanged(v);
}), }),
); );
}), }),