feat: Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:krow/core/presentation/widgets/ui_kit/kw_input.dart';
|
||||
import 'package:krow/features/create_event/domain/bloc/create_event_bloc.dart';
|
||||
|
||||
class AddInfoInputWidget extends StatefulWidget {
|
||||
const AddInfoInputWidget({super.key});
|
||||
|
||||
@override
|
||||
State<AddInfoInputWidget> createState() => _AddInfoInputWidgetState();
|
||||
}
|
||||
|
||||
class _AddInfoInputWidgetState extends State<AddInfoInputWidget> {
|
||||
final TextEditingController _addInfoController = TextEditingController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocConsumer<CreateEventBloc, CreateEventState>(
|
||||
listener: (context, state) {
|
||||
if (state.entity.additionalInfo != _addInfoController.text) {
|
||||
_addInfoController.text = state.entity.additionalInfo??'';
|
||||
}
|
||||
},
|
||||
buildWhen: (previous, current) {
|
||||
return previous.entity.additionalInfo != current.entity.additionalInfo;
|
||||
},
|
||||
builder: (context, state) {
|
||||
return KwTextInput(
|
||||
controller: _addInfoController,
|
||||
onChanged: (value) {
|
||||
BlocProvider.of<CreateEventBloc>(context)
|
||||
.add(CreateEventAddInfoChange(value));
|
||||
},
|
||||
maxLength: 300,
|
||||
showCounter: true,
|
||||
minHeight: 144,
|
||||
hintText: 'Enter your main text here...',
|
||||
title: 'Additional Information',
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
|
||||
import 'package:krow/core/presentation/styles/theme.dart';
|
||||
import 'package:krow/features/create_event/domain/bloc/create_event_bloc.dart';
|
||||
|
||||
class AddonsSectionWidget extends StatelessWidget {
|
||||
const AddonsSectionWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<CreateEventBloc, CreateEventState>(
|
||||
builder: (context, state) {
|
||||
var allAddons = state.addons;
|
||||
var selectedAddons = state.entity.addons;
|
||||
if(context.read<CreateEventBloc>().state.addons.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Column(
|
||||
children: [
|
||||
const Divider(
|
||||
height: 0,
|
||||
color: AppColors.grayStroke,
|
||||
),
|
||||
for (var addon in allAddons)
|
||||
_addonStrokeItem(
|
||||
title: addon.name ?? '',
|
||||
enabled: selectedAddons
|
||||
?.any((selected) => selected.id == addon.id) ??
|
||||
false,
|
||||
onTap: () {
|
||||
BlocProvider.of<CreateEventBloc>(context)
|
||||
.add(CreateEventToggleAddon(addon));
|
||||
},
|
||||
),
|
||||
const Gap(12),
|
||||
const Divider(
|
||||
height: 0,
|
||||
color: AppColors.grayStroke,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
_addonStrokeItem(
|
||||
{required String title,
|
||||
required bool enabled,
|
||||
required VoidCallback onTap}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: AppTextStyles.bodyMediumMed,
|
||||
)),
|
||||
CupertinoSwitch(
|
||||
value: enabled,
|
||||
onChanged: (_) {
|
||||
onTap();
|
||||
},
|
||||
activeTrackColor: AppColors.bgColorDark,
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:krow/core/data/models/event/hub_model.dart';
|
||||
import 'package:krow/core/presentation/styles/kw_box_decorations.dart';
|
||||
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
|
||||
import 'package:krow/core/presentation/styles/theme.dart';
|
||||
import 'package:krow/core/presentation/widgets/ui_kit/kw_dropdown.dart';
|
||||
import 'package:krow/core/presentation/widgets/ui_kit/kw_input.dart';
|
||||
import 'package:krow/features/create_event/domain/bloc/create_event_bloc.dart';
|
||||
import 'package:krow/features/create_event/presentation/event_date_section/event_date_input_widget.dart';
|
||||
|
||||
import '../../../../core/entity/event_entity.dart';
|
||||
|
||||
class CreateEventDetailsCardWidget extends StatefulWidget {
|
||||
const CreateEventDetailsCardWidget({super.key});
|
||||
|
||||
@override
|
||||
State<CreateEventDetailsCardWidget> createState() =>
|
||||
_CreateEventDetailsCardWidgetState();
|
||||
}
|
||||
|
||||
class _CreateEventDetailsCardWidgetState
|
||||
extends State<CreateEventDetailsCardWidget>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
TextEditingController poNumberController = TextEditingController();
|
||||
// TextEditingController contractNumberController = TextEditingController();
|
||||
final TextEditingController _nameController = TextEditingController();
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return BlocConsumer<CreateEventBloc, CreateEventState>(
|
||||
listener: (context, state) {
|
||||
if (state.entity.name != _nameController.text) {
|
||||
_nameController.text = state.entity.name;
|
||||
}
|
||||
|
||||
// if (state.entity.contractNumber != null &&
|
||||
// state.entity.contractNumber != contractNumberController.text) {
|
||||
// contractNumberController.text = state.entity.contractNumber!;
|
||||
// }
|
||||
//
|
||||
if (state.entity.poNumber != null &&
|
||||
state.entity.poNumber != poNumberController.text) {
|
||||
poNumberController.text = state.entity.poNumber!;
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return AnimatedContainer(
|
||||
duration: Duration(milliseconds: 300),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 24),
|
||||
decoration: KwBoxDecorations.white12.copyWith(
|
||||
border: state.validationState != null
|
||||
? Border.all(color: AppColors.statusError, width: 1)
|
||||
: null),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Event Details',
|
||||
style: AppTextStyles.bodyMediumMed,
|
||||
),
|
||||
const Gap(12),
|
||||
KwTextInput(
|
||||
controller: _nameController,
|
||||
title: 'Event Name',
|
||||
hintText: 'Enter event name',
|
||||
onChanged: (value) {
|
||||
BlocProvider.of<CreateEventBloc>(context)
|
||||
.add(CreateEventNameChange(value));
|
||||
},
|
||||
),
|
||||
IgnorePointer(
|
||||
ignoring: ![EventStatus.draft, EventStatus.pending].contains(state.entity.status) && state.entity.status!=null,
|
||||
child: EventDateInputWidget(state.entity)),
|
||||
const Gap(8),
|
||||
_hubDropdown(state.hubs, state),
|
||||
const Gap(8),
|
||||
// _contractDropdown(context, state),
|
||||
// if (state.entity.contractType == EventContractType.contract)
|
||||
// _buildContractInput(),
|
||||
// if (state.entity.contractType == EventContractType.purchaseOrder)
|
||||
_buildPurchaseInput(),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Column _hubDropdown(List<HubModel> hubs, CreateEventState state) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 16),
|
||||
child: Text(
|
||||
'Location',
|
||||
style:
|
||||
AppTextStyles.bodyTinyReg.copyWith(color: AppColors.blackGray),
|
||||
),
|
||||
),
|
||||
const Gap(4),
|
||||
KwDropdown(
|
||||
horizontalPadding: 28,
|
||||
hintText: 'Hub name',
|
||||
selectedItem: state.entity.hub != null
|
||||
? KwDropDownItem(
|
||||
data: state.entity.hub, title: state.entity.hub?.name ?? '')
|
||||
: null,
|
||||
items: hubs
|
||||
.map((e) => KwDropDownItem(data: e, title: e.name ?? ''))
|
||||
.toList(),
|
||||
onSelected: (item) {
|
||||
BlocProvider.of<CreateEventBloc>(context)
|
||||
.add(CreateEventChangeHub(item!));
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// Column _contractDropdown(BuildContext context, CreateEventState state) {
|
||||
// return Column(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// Padding(
|
||||
// padding: const EdgeInsets.only(left: 16),
|
||||
// child: Text(
|
||||
// 'Payment type',
|
||||
// style:
|
||||
// AppTextStyles.bodyTinyReg.copyWith(color: AppColors.blackGray),
|
||||
// ),
|
||||
// ),
|
||||
// const Gap(4),
|
||||
// KwDropdown(
|
||||
// horizontalPadding: 28,
|
||||
// hintText: 'Direct',
|
||||
// selectedItem: KwDropDownItem(
|
||||
// data: state.entity.contractType,
|
||||
// title: state.entity.contractType.formattedName),
|
||||
// items: const [
|
||||
// KwDropDownItem(data: EventContractType.direct, title: 'Direct'),
|
||||
// KwDropDownItem(
|
||||
// data: EventContractType.purchaseOrder,
|
||||
// title: 'Purchase Order'),
|
||||
// KwDropDownItem(
|
||||
// data: EventContractType.contract, title: 'Contract'),
|
||||
// ],
|
||||
// onSelected: (item) {
|
||||
// BlocProvider.of<CreateEventBloc>(context)
|
||||
// .add(CreateEventChangeContractType(item));
|
||||
// }),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// _buildContractInput() {
|
||||
// return Padding(
|
||||
// padding: const EdgeInsets.only(top:8.0),
|
||||
// child: KwTextInput(
|
||||
// controller: contractNumberController,
|
||||
// onChanged: (value) {
|
||||
// BlocProvider.of<CreateEventBloc>(context)
|
||||
// .add(CreateEventChangeContractNumber(value));
|
||||
// },
|
||||
// title: 'Contract number',
|
||||
// hintText: '#00000'),
|
||||
// );
|
||||
// }
|
||||
//
|
||||
_buildPurchaseInput() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top:8.0),
|
||||
child: KwTextInput(
|
||||
controller: poNumberController,
|
||||
onChanged: (value) {
|
||||
BlocProvider.of<CreateEventBloc>(context)
|
||||
.add(CreateEventChangePoNumber(value));
|
||||
},
|
||||
title: 'PO Reference number',
|
||||
hintText: 'PO Reference number'),
|
||||
);
|
||||
}
|
||||
}
|
||||
//
|
||||
// extension on EventContractType? {
|
||||
// String get formattedName {
|
||||
// return switch (this) {
|
||||
// EventContractType.direct => 'Direct',
|
||||
// EventContractType.contract => 'Contract',
|
||||
// EventContractType.purchaseOrder => 'Purchase Order',
|
||||
// null => 'null'
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,136 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:krow/core/data/models/event/tag_model.dart';
|
||||
import 'package:krow/core/presentation/gen/assets.gen.dart';
|
||||
import 'package:krow/core/presentation/styles/kw_box_decorations.dart';
|
||||
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
|
||||
import 'package:krow/core/presentation/styles/theme.dart';
|
||||
import 'package:krow/features/create_event/domain/bloc/create_event_bloc.dart';
|
||||
|
||||
class CreateEventTagsCard extends StatelessWidget {
|
||||
const CreateEventTagsCard({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<CreateEventBloc, CreateEventState>(
|
||||
buildWhen: (previous, current) =>
|
||||
previous.tags != current.tags ||
|
||||
previous.entity.tags != current.entity.tags,
|
||||
builder: (context, state) {
|
||||
if(state.tags.isEmpty) return const SizedBox();
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(top: 12),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 24),
|
||||
decoration: KwBoxDecorations.white12,
|
||||
child: _buildChips(context, state.tags, state.entity.tags ?? []),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildChips(BuildContext context, List<TagModel> allTags,
|
||||
List<TagModel> selectedTags) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 12),
|
||||
child: Wrap(
|
||||
runSpacing: 8,
|
||||
spacing: 8,
|
||||
children: allTags
|
||||
.map((e) =>
|
||||
_buildTag(context, e, selectedTags.any((t) => e.id == t.id)))
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTag(BuildContext context, TagModel tag, bool selected) {
|
||||
const duration = Duration(milliseconds: 150);
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
BlocProvider.of<CreateEventBloc>(context)
|
||||
.add(CreateEventTagSelected(tag));
|
||||
},
|
||||
child: AnimatedContainer(
|
||||
duration: duration,
|
||||
padding: const EdgeInsets.all(8),
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: selected ? AppColors.blackBlack : AppColors.grayTintStroke,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AnimatedContainer(
|
||||
duration: duration,
|
||||
height: 28,
|
||||
width: 28,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: selected ? AppColors.blackBlack : AppColors.tintGray,
|
||||
),
|
||||
child: Center(
|
||||
child: getImageById(tag.id).svg(
|
||||
width: 12.0,
|
||||
height: 12.0,
|
||||
colorFilter: ColorFilter.mode(
|
||||
selected ? AppColors.grayWhite : AppColors.blackBlack,
|
||||
BlendMode.srcIn)),
|
||||
),
|
||||
),
|
||||
const Gap(8),
|
||||
Text(
|
||||
tag.name,
|
||||
style: AppTextStyles.bodySmallReg
|
||||
.copyWith(color: AppColors.bgColorDark),
|
||||
),
|
||||
const Gap(8),
|
||||
AnimatedContainer(
|
||||
duration: duration,
|
||||
height: 16,
|
||||
width: 16,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: selected
|
||||
? AppColors.blackBlack
|
||||
: AppColors.grayTintStroke,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: AnimatedContainer(
|
||||
duration: duration,
|
||||
height: 6,
|
||||
width: 6,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color:
|
||||
selected ? AppColors.blackBlack : Colors.transparent,
|
||||
)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
getImageById(String id) {
|
||||
switch (id) {
|
||||
case '1':
|
||||
return Assets.images.icons.tags.award;
|
||||
case '2':
|
||||
return Assets.images.icons.tags.briefcase;
|
||||
case '3':
|
||||
return Assets.images.icons.tags.flash;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
|
||||
import 'package:krow/core/presentation/styles/theme.dart';
|
||||
|
||||
class CreateEventTitleWidget extends StatelessWidget {
|
||||
const CreateEventTitleWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Gap(8),
|
||||
const Text('Create Your Event', style: AppTextStyles.headingH1),
|
||||
const Gap(8),
|
||||
Text(
|
||||
'Bring your vision to life! Share details, set the stage, and connect with your audience—your event starts here.',
|
||||
style:
|
||||
AppTextStyles.bodyMediumReg.copyWith(color: AppColors.blackGray),
|
||||
),
|
||||
const Gap(24),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:krow/core/presentation/styles/kw_text_styles.dart';
|
||||
import 'package:krow/core/presentation/styles/theme.dart';
|
||||
import 'package:krow/features/create_event/domain/bloc/create_event_bloc.dart';
|
||||
|
||||
class TotalCostRowWidget extends StatelessWidget {
|
||||
TotalCostRowWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<CreateEventBloc, CreateEventState>(
|
||||
builder: (context, state) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Approximate Total Costs',
|
||||
style: AppTextStyles.bodyMediumReg
|
||||
.copyWith(color: AppColors.blackGray),
|
||||
),
|
||||
ValueListenableBuilder(
|
||||
valueListenable: state.entity.totalCost,
|
||||
builder: (context, value, child) {
|
||||
return Text(
|
||||
'\$${value.toStringAsFixed(2)}',
|
||||
style: AppTextStyles.bodyMediumMed,
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user