Untitled
import 'package:Buildeffective/src/utils/comman_export.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:nb_utils/nb_utils.dart'; class BreadCrumbWidget extends StatelessWidget { final List<String>? previousValue; final List<Widget>? action; final String? currentValue; const BreadCrumbWidget({Key? key, this.previousValue, this.currentValue, this.action}) : super(key: key); @override Widget build(BuildContext context) { List<Widget> breadcrumbItems = []; // Build the separator widget Widget buildSeparatorWidget({Color? color}) { return Padding( padding: const EdgeInsets.symmetric(horizontal: 2.0), child: SvgPicture.asset( ResImages.ic_spacelisting_arrow, // Replace with actual path for 'ResImages.ic_spacelisting_arrow' color: color ?? Colors.white, // Default color is white unless specified ), ); } // Copy previousValue to a new list to handle the case where we modify it List<String> previous = List.from(previousValue ?? []); // If currentValue is null and previousValue has values, use the first previous value as the current String? effectiveCurrentValue = currentValue; if (effectiveCurrentValue == null && previous.isNotEmpty) { effectiveCurrentValue = previous.removeAt(0); // Set the first item as current and remove it from previous list } // Handle the previous breadcrumbs (list of previous items) if (previous.isNotEmpty) { for (int i = 0; i < previous.length; i++) { breadcrumbItems.add( GestureDetector( onTap: () { // Handle onTap for this breadcrumb (navigation logic here) print('Tapped on ${previous[i]}'); }, child: Text( previous[i], style: BETextStyles.LinkStyleWithGrey3Color, // Custom style for previous breadcrumbs ), ), ); if (i != previous.length - 1) { breadcrumbItems.add(buildSeparatorWidget(color: BEColors.grey3Color)); } // Add a separator after each breadcrumb except the last one } } // Handle the current value (effectiveCurrentValue will never be null at this point) if (effectiveCurrentValue != null && effectiveCurrentValue.isNotEmpty) { if (previous.isNotEmpty) { // Add a separator before currentValue if there are previous breadcrumbs breadcrumbItems.add(buildSeparatorWidget()); } breadcrumbItems.add( Text( effectiveCurrentValue, style: BETextStyles.LinkStyleWithWhiteColor, // Custom style for current breadcrumb ), ); } // If there's no previousValue and currentValue is null, display nothing if (breadcrumbItems.isEmpty) { return const SizedBox.shrink(); // Return an empty widget } if (action != null) { return Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Align( alignment: Alignment.centerLeft, child: HorizontalList( reverse: previous.isNotEmpty, crossAxisAlignment: WrapCrossAlignment.center, wrapAlignment: WrapAlignment.center, padding: EdgeInsets.symmetric(horizontal: 16), itemBuilder: (context, index) { return breadcrumbItems[index]; }, itemCount: breadcrumbItems.length, ), ).expand(), 16.width, ...action! ], ); } return SingleChildScrollView( scrollDirection: Axis.horizontal, reverse: true, padding: EdgeInsets.symmetric(horizontal: 16), child: Row( mainAxisSize: MainAxisSize.min, children: breadcrumbItems, ), ); } }
Leave a Comment