0% found this document useful (0 votes)
14 views7 pages

Custom Card

The document contains a Flutter widget called CustomContainerBox, which is a stateful widget designed to display a customizable container with various functionalities such as viewing, updating, deleting, and deactivating items. It includes features like dynamic text avatars, a popup menu for actions, and the ability to show a limited number of items with an option to view more or less. The widget is styled with padding, shadows, and responsive design elements using the ScreenUtil package for better adaptability across different screen sizes.

Uploaded by

Shiva.P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views7 pages

Custom Card

The document contains a Flutter widget called CustomContainerBox, which is a stateful widget designed to display a customizable container with various functionalities such as viewing, updating, deleting, and deactivating items. It includes features like dynamic text avatars, a popup menu for actions, and the ability to show a limited number of items with an option to view more or less. The widget is styled with padding, shadows, and responsive design elements using the ScreenUtil package for better adaptability across different screen sizes.

Uploaded by

Shiva.P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:iconsax/iconsax.dart';
import 'package:rakaz_application/Helper/utils/Constants/constants.dart';
import 'package:skeletonizer/skeletonizer.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../../Helper/utils/Constants/ImageConstants.dart';
import '../../../Helper/utils/WidgetStyles/CustomWidgets.dart';
import '../CustomAvatarForFirstLetter.dart';

class CustomContainerBox extends StatefulWidget {


final String name;
final int? activeName;
final List<SubContentAdmin> subcontent;
final List<dynamic>? values;
final List<String>? keys;
final bool delete;
final bool? deactivate;
final bool? dynamicTextAvatar;
final bool? menu;
final bool? update;
final bool? view;
final Function? viewFunction;
final Function? updateFunction;
final Function? deleteFunction;
final Function? deActiveFunction;
final int initialItemsToShow;
final bool? moreButton;

const CustomContainerBox({
Key? key,
required this.name,
this.activeName,
required this.subcontent,
this.viewFunction,
this.updateFunction,
this.deleteFunction,
this.deActiveFunction,
this.values,
this.keys,
required this.delete,
this.deactivate = true,
this.view = true,
this.update = true,
this.menu = true,
this.initialItemsToShow = 4,
this.moreButton = true,
this.dynamicTextAvatar = false,
}) : super(key: key);

@override
State<CustomContainerBox> createState() => _CustomContainerBoxState();
}

class _CustomContainerBoxState extends State<CustomContainerBox> {


bool _showAllItems = false;
@override
void initState() {
// TODO: implement initState
super.initState();
}

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(
left: 16.0, right: 16.0, bottom: 10.0, top: 10.0)
.r,
child: Container(
width: double.infinity,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Theme.of(context).primaryColor,
blurRadius: 8.r,
spreadRadius: 2,
offset: Offset(4, 4),
),
],
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(7).r,
// border: Border.all( width: 2.w),
// color: Colors.white,
),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 15).r,
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
widget.activeName != null
? Row(
children: [
Skeleton.shade(
child: Column(
children: [
CustomWidgets.circle(widget.activeName),
],
),
),
SizedBox(
width: 20.w,
),
],
)
: SizedBox(),
widget.dynamicTextAvatar!
? DynamicAvatarText(
text: widget.name,
)
: SizedBox(),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: 280.w,
child: Text(
widget.name.toUpperCase(),
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 19.sp,
// color: Colors.black,
),
),
),
widget.activeName != null
? CustomWidgets.color(widget.activeName)
: SizedBox(),
],
),
Spacer(),
if (widget.menu!)
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
PopupMenuButton<String>(
offset: Offset(0, 30),
itemBuilder: (BuildContext context) {
return [
if (widget.update!)
PopupMenuItem(
onTap: () {
widget.updateFunction!();
},
value: 'edit',
child: SizedBox(
width: 130.w,
child: Row(
children: [
Icon(
Iconsax.edit,
size: 20,
// color: widget.activeName == 0
// ? Theme.of(context)
// .disabledColor
// : null,
),
SizedBox(width: 10),
Text(
'Update',
style: TextStyle(
// color: widget.activeName == 0
// ? Theme.of(context)
// .disabledColor
// : null,
),
),
],
),
),
),
if (widget.view!)
PopupMenuItem(
onTap: () {
widget.viewFunction!();
},
value: 'View',
child: SizedBox(
width: 130.w,
child: Row(
children: [
Icon(
Iconsax.eye,
// color: widget.activeName == 0
// ? Theme.of(context)
// .disabledColor
// : null,
),
SizedBox(width: 10),
Text(
'View',
style: TextStyle(
// color: widget.activeName == 0
// ? Theme.of(context)
// .disabledColor
// : null,
),
),
],
),
),
),
if (widget.delete)
PopupMenuItem(
onTap: () {
widget.deleteFunction!();
},
value: 'Delete',
child: SizedBox(
width: 130.w,
child: Row(
children: [
Icon(
Icons.delete_outline,
// color: widget.activeName == 0
// ? Theme.of(context)
// .disabledColor
// : null,
),
SizedBox(width: 10),
Text(
'Delete',
style: TextStyle(
// color: widget.activeName == 0
// ? Theme.of(context)
// .disabledColor
// : null,
),
),
],
),
),
),
if (widget.deactivate!)
PopupMenuItem(
onTap: () {
widget.deActiveFunction!();
},
child: SizedBox(
width: 130.w,
child: Row(
children: [
Icon(
Icons.not_interested,
// color: widget.activeName == 0
// ?
Theme.of(context).disabledColor
// : null,
),
SizedBox(width: 17),
Text(
widget.activeName == 0
? 'Active'
: 'Deactivate',
style: TextStyle(
// color: Colors.black,
),
),
],
),
),
),
];
},
child: Image.asset(
ImageConstants.dots,
color: Theme.of(context).hintColor,
),
// surfaceTintColor: Constants.white,
),
SizedBox(
height: 33.h,
),
],
),
),
],
),
SizedBox(
height: 10.h,
),
widget.keys != null && widget.values != null
? widget.keys!.isNotEmpty && widget.values!.isNotEmpty
? Column(
children: List.generate(
_showAllItems
? widget.keys!.length
: min(widget.initialItemsToShow,
widget.keys!.length), (index) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.keys![index],
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w400,
),
),
SizedBox(
width: 10.w,
),
Flexible(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
if (widget.values![index] is List<String>)
Text(
(widget.values![index]
as List<String>)
.join(","),
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w500,
),
)
else if (widget.values![index] is String)
Text(
(widget.values![index] as String)
.toLowerCase(),
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w500,
),
)
else
Text(
widget.values![index].toString(),
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w500,
),
),
],
),
),
],
);
}),
)
: SizedBox()
: SizedBox(),
if (widget.keys!.length > 4)
widget.moreButton!
? Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
_showAllItems
? TextButton(
onPressed: () =>
setState(() => _showAllItems = false),
child: Text(
"View Less <<",
style: TextStyle(
fontSize: 16.sp,
color: Colors.blue,
fontWeight: FontWeight.bold,
),
),
)
: TextButton(
onPressed: () =>
setState(() => _showAllItems = true),
child: Text(
"View More >>",
style: TextStyle(
fontSize: 16.sp,
color: Colors.blue,
fontWeight: FontWeight.bold,
),
),
),
],
)
: SizedBox(
height: 10.h,
),
],
),
),
),
);
}
}

You might also like