Skip to content

Commit f2f7699

Browse files
committed
💄 Improve scaling with select indicators and numbers
Resolves #253.
1 parent 4bf0c7e commit f2f7699

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,38 +1965,41 @@ class DefaultAssetPickerBuilderDelegate
19651965

19661966
@override
19671967
Widget selectIndicator(BuildContext context, int index, AssetEntity asset) {
1968+
final double indicatorSize = context.mediaQuery.size.width / gridCount / 3;
19681969
final Duration duration = switchingPathDuration * 0.75;
19691970
return Selector<DefaultAssetPickerProvider, String>(
19701971
selector: (_, DefaultAssetPickerProvider p) => p.selectedDescriptions,
19711972
builder: (BuildContext context, String descriptions, __) {
19721973
final bool selected = descriptions.contains(asset.toString());
1973-
final double indicatorSize =
1974-
context.mediaQuery.size.width / gridCount / 3;
19751974
final Widget innerSelector = AnimatedContainer(
19761975
duration: duration,
19771976
width: indicatorSize / (isAppleOS ? 1.25 : 1.5),
19781977
height: indicatorSize / (isAppleOS ? 1.25 : 1.5),
1978+
padding: EdgeInsets.all(indicatorSize / 10),
19791979
decoration: BoxDecoration(
1980-
border:
1981-
!selected ? Border.all(color: Colors.white, width: 2) : null,
1980+
border: !selected
1981+
? Border.all(
1982+
color: context.themeData.selectedRowColor,
1983+
width: indicatorSize / 25,
1984+
)
1985+
: null,
19821986
color: selected ? themeColor : null,
19831987
shape: BoxShape.circle,
19841988
),
1985-
child: AnimatedSwitcher(
1986-
duration: duration,
1987-
reverseDuration: duration,
1988-
child: selected
1989-
? const Icon(Icons.check, size: 18)
1990-
: const SizedBox.shrink(),
1989+
child: FittedBox(
1990+
child: AnimatedSwitcher(
1991+
duration: duration,
1992+
reverseDuration: duration,
1993+
child:
1994+
selected ? const Icon(Icons.check) : const SizedBox.shrink(),
1995+
),
19911996
),
19921997
);
19931998
final Widget selectorWidget = GestureDetector(
19941999
behavior: HitTestBehavior.opaque,
19952000
onTap: () => selectAsset(context, asset, selected),
19962001
child: Container(
1997-
margin: EdgeInsets.all(
1998-
context.mediaQuery.size.width / gridCount / 12,
1999-
),
2002+
margin: EdgeInsets.all(indicatorSize / 4),
20002003
width: isPreviewEnabled ? indicatorSize : null,
20012004
height: isPreviewEnabled ? indicatorSize : null,
20022005
alignment: AlignmentDirectional.topEnd,
@@ -2019,6 +2022,7 @@ class DefaultAssetPickerBuilderDelegate
20192022

20202023
@override
20212024
Widget selectedBackdrop(BuildContext context, int index, AssetEntity asset) {
2025+
final double indicatorSize = context.mediaQuery.size.width / gridCount / 3;
20222026
return Positioned.fill(
20232027
child: GestureDetector(
20242028
onTap: isPreviewEnabled
@@ -2030,22 +2034,28 @@ class DefaultAssetPickerBuilderDelegate
20302034
final bool selected = index != -1;
20312035
return AnimatedContainer(
20322036
duration: switchingPathDuration,
2037+
padding: EdgeInsets.all(indicatorSize * .35),
20332038
color: selected
20342039
? theme.colorScheme.primary.withOpacity(.45)
2035-
: Colors.black.withOpacity(.1),
2040+
: theme.backgroundColor.withOpacity(.1),
20362041
child: selected && !isSingleAssetMode
2037-
? Container(
2042+
? Align(
20382043
alignment: AlignmentDirectional.topStart,
2039-
padding: const EdgeInsets.all(14),
2040-
child: ScaleText(
2041-
'${index + 1}',
2042-
style: TextStyle(
2043-
color: theme.textTheme.bodyText1?.color
2044-
?.withOpacity(.75),
2045-
fontWeight: FontWeight.w600,
2046-
height: 1,
2044+
child: SizedBox(
2045+
height: indicatorSize / 2.5,
2046+
child: FittedBox(
2047+
alignment: AlignmentDirectional.topStart,
2048+
fit: BoxFit.cover,
2049+
child: Text(
2050+
'${index + 1}',
2051+
style: TextStyle(
2052+
color: theme.textTheme.bodyText1?.color
2053+
?.withOpacity(.75),
2054+
fontWeight: FontWeight.w600,
2055+
height: 1,
2056+
),
2057+
),
20472058
),
2048-
maxScaleFactor: 1.4,
20492059
),
20502060
)
20512061
: const SizedBox.shrink(),

0 commit comments

Comments
 (0)