segment static method

LLSegmentTranslations segment(
  1. BuildContext context,
  2. String segment, {
  3. bool ensure = true,
})

THE preferred accessor. Depends on one segment, and asks for it to be loaded.

Do not mix this with of in the same widget: an element's aspect set is cumulative for its lifetime, and one aspect-less dependency permanently degrades that element to rebuilding on every change.

Implementation

static LLSegmentTranslations segment(
  BuildContext context,
  String segment, {
  bool ensure = true,
}) {
  final LLContentModel? model = InheritedModel.inheritFrom<LLContentModel>(
    context,
    aspect: LLAspect.segment(segment),
  );
  if (model == null) {
    return LLSegmentTranslations._(
      null,
      segment,
      'en',
      TextDirection.ltr,
      LLSegmentState.idle,
    );
  }
  if (ensure) model.client.ensureSegments(<String>[segment]);
  return LLSegmentTranslations._(
    model.client,
    segment,
    model.language,
    model.direction == LLTextDirection.rtl
        ? TextDirection.rtl
        : TextDirection.ltr,
    model.segmentStates[segment] ?? LLSegmentState.idle,
  );
}