getWidget method

  1. @override
Widget getWidget(
  1. BuildContext context, {
  2. VoidCallback? onDeleteItem,
  3. VoidCallback? onFavoriteChanged,
})
override

Displays the list item.

onDeleteItem is called when the user asks to remove the item. Without it, the item cannot be removed. onFavoriteChanged is called once the item changed its favorite status.

Implementation

@override
Widget getWidget(
  BuildContext context, {
  VoidCallback? onDeleteItem,
  VoidCallback? onFavoriteChanged,
}) {
  final SmoothColorsThemeExtension extension = context
      .extension<SmoothColorsThemeExtension>();
  final bool lightTheme = context.lightTheme();

  final String? name = osmLocation.name;
  final String? street = osmLocation.street;
  final String? address = _address;
  final String title = name ?? street ?? address ?? osmLocation.primaryKey;

  final _SearchLocationMenu menu = _SearchLocationMenu(
    osmLocation: osmLocation,
    title: title,
    popFirst: popFirst,
    onSelect: () => _select(context),
    onDeleteItem: onDeleteItem,
    onFavoriteChanged: onFavoriteChanged,
  );

  return SmoothCard(
    elevation: 5.0,
    elevationColor: Colors.black26,
    margin: const EdgeInsetsDirectional.only(
      top: MEDIUM_SPACE,
      start: SMALL_SPACE,
      end: SMALL_SPACE,
    ),
    padding: EdgeInsets.zero,
    color: lightTheme ? null : extension.primaryUltraBlack,
    child: InkWell(
      borderRadius: ROUNDED_BORDER_RADIUS,
      onTap: () => _select(context),
      onLongPress: () => menu.show(context),
      child: DefaultTextStyle.merge(
        style: TextStyle(color: extension.primaryBlack, fontSize: 15.0),
        child: IconTheme.merge(
          data: IconThemeData(
            color: lightTheme
                ? extension.primaryNormal
                : extension.primaryMedium,
            size: 20.0,
          ),
          child: Stack(
            children: <Widget>[
              Padding(
                padding: const EdgeInsetsDirectional.symmetric(
                  horizontal: _horizontalPadding,
                  vertical: _verticalPadding,
                ),
                child: Column(
                  spacing: SMALL_SPACE,
                  children: <Widget>[
                    Row(
                      spacing: VERY_SMALL_SPACE,
                      children: <Widget>[
                        Expanded(
                          child: PriceDataEntry(
                            icon: OsmLocationKind.of(osmLocation).icon,
                            label: title,
                            labelStyle: const TextStyle(
                              fontWeight: FontWeight.w600,
                            ),
                            labelPadding: const EdgeInsetsDirectional.only(
                              bottom: 2.5,
                            ),
                          ),
                        ),
                        // The heart is drawn above, with a larger tap area
                        const SizedBox.square(
                          dimension: _SearchLocationFavoriteItem.size,
                        ),
                      ],
                    ),
                    if (name != null && street != null)
                      PriceDataEntry(
                        icon: const icons.Street.road(),
                        label: street,
                        labelPadding: const EdgeInsetsDirectional.only(
                          bottom: 2.5,
                        ),
                      ),
                    Row(
                      spacing: VERY_SMALL_SPACE,
                      children: <Widget>[
                        Expanded(
                          child: address == null || address == title
                              ? EMPTY_WIDGET
                              : PriceDataEntry(
                                  icon: const icons.Location(),
                                  label: address,
                                  labelPadding:
                                      const EdgeInsetsDirectional.only(
                                        bottom: 2.5,
                                      ),
                                ),
                        ),
                        menu,
                      ],
                    ),
                  ],
                ),
              ),
              PositionedDirectional(
                top:
                    _verticalPadding +
                    _SearchLocationFavoriteItem.iconPadding -
                    _SearchLocationFavoriteItem.tapPadding,
                end:
                    _horizontalPadding +
                    _SearchLocationFavoriteItem.iconPadding -
                    _SearchLocationFavoriteItem.tapPadding,
                child: _SearchLocationFavoriteItem(
                  osmLocation: osmLocation,
                  onTap: onFavoriteChanged,
                ),
              ),
            ],
          ),
        ),
      ),
    ),
  );
}