From 778ab12de0189c2c921c82702d4419ae7b85969e Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Mon, 23 Sep 2024 15:45:14 +0200 Subject: [PATCH] added autosize text --- .../widget_item_list_exposure_pairs.dart | 66 ++++++++++++++----- pubspec.yaml | 1 + 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/lib/screens/metering/components/shared/exposure_pairs_list/components/exposure_pairs_list_item/widget_item_list_exposure_pairs.dart b/lib/screens/metering/components/shared/exposure_pairs_list/components/exposure_pairs_list_item/widget_item_list_exposure_pairs.dart index 9aeb108..e6ca4b1 100644 --- a/lib/screens/metering/components/shared/exposure_pairs_list/components/exposure_pairs_list_item/widget_item_list_exposure_pairs.dart +++ b/lib/screens/metering/components/shared/exposure_pairs_list/components/exposure_pairs_list_item/widget_item_list_exposure_pairs.dart @@ -1,3 +1,4 @@ +import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:lightmeter/res/dimens.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; @@ -15,22 +16,9 @@ class ExposurePairsListItem extends StatelessWid @override Widget build(BuildContext context) { final List rowChildren = [ - Flexible( - child: Text( - value.toString(), - style: labelTextStyle(context).copyWith(color: Theme.of(context).colorScheme.onBackground), - softWrap: false, - overflow: TextOverflow.fade, - ), - ), + _Title(value), const SizedBox(width: Dimens.grid8), - ColoredBox( - color: Theme.of(context).colorScheme.onBackground, - child: SizedBox( - height: 1, - width: tickLength(), - ), - ), + if (value.stopType == StopType.full) const _Tick.full() else const _Tick.short(), if (value.stopType != StopType.full) const SizedBox(width: Dimens.grid4), ]; return Row( @@ -59,3 +47,51 @@ class ExposurePairsListItem extends StatelessWid } } } + +class _Title extends StatelessWidget { + final T value; + + const _Title(this.value, {super.key}); + + @override + Widget build(BuildContext context) { + return Flexible( + child: AutoSizeText( + value.toString(), + stepGranularity: 0.5, + style: labelTextStyle(context).copyWith(color: Theme.of(context).colorScheme.onBackground), + softWrap: false, + overflow: TextOverflow.fade, + maxLines: 1, + ), + ); + } + + TextStyle labelTextStyle(BuildContext context) { + switch (value.stopType) { + case StopType.full: + return Theme.of(context).textTheme.bodyLarge!; + case StopType.half: + case StopType.third: + return Theme.of(context).textTheme.bodyMedium!; + } + } +} + +class _Tick extends StatelessWidget { + final double _length; + + const _Tick.full() : _length = Dimens.grid16; + const _Tick.short() : _length = Dimens.grid8; + + @override + Widget build(BuildContext context) { + return ColoredBox( + color: Theme.of(context).colorScheme.onBackground, + child: SizedBox( + height: 1, + width: _length, + ), + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index e977ecc..9a5917b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,6 +8,7 @@ environment: dependencies: app_settings: 4.2.0 + auto_size_text: 3.0.0 bloc_concurrency: 0.2.2 camera: 0.10.5+2 camera_android_camerax: 0.6.1+1