fixed primary color picker overscroll

This commit is contained in:
Vadim 2023-02-04 22:56:51 +03:00
parent 00e104de9b
commit b5ebc09d68

View file

@ -13,10 +13,7 @@ class PrimaryColorDialogPicker extends StatefulWidget {
class _PrimaryColorDialogPickerState extends State<PrimaryColorDialogPicker> { class _PrimaryColorDialogPickerState extends State<PrimaryColorDialogPicker> {
late Color _selected = Theme.of(context).primaryColor; late Color _selected = Theme.of(context).primaryColor;
late final ScrollController _scrollController = ScrollController( final ScrollController _scrollController = ScrollController();
initialScrollOffset:
ThemeProvider.primaryColorsList.indexOf(_selected) * (Dimens.grid48 + Dimens.grid8),
);
@override @override
void dispose() { void dispose() {
@ -37,15 +34,18 @@ class _PrimaryColorDialogPickerState extends State<PrimaryColorDialogPicker> {
content: SizedBox( content: SizedBox(
height: Dimens.grid48, height: Dimens.grid48,
width: double.maxFinite, width: double.maxFinite,
child: ListView.separated( child: SingleChildScrollView(
controller: _scrollController, controller: _scrollController,
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
separatorBuilder: (_, __) => const SizedBox(width: Dimens.grid8), child: Row(
itemCount: ThemeProvider.primaryColorsList.length, children: List.generate(
itemBuilder: (_, index) { ThemeProvider.primaryColorsList.length,
(index) {
final color = ThemeProvider.primaryColorsList[index]; final color = ThemeProvider.primaryColorsList[index];
return _SelectableColorItem( return Padding(
padding: EdgeInsets.only(left: index == 0 ? 0 : Dimens.paddingS),
child: _SelectableColorItem(
color: color, color: color,
selected: color.value == _selected.value, selected: color.value == _selected.value,
onTap: () { onTap: () {
@ -53,10 +53,13 @@ class _PrimaryColorDialogPickerState extends State<PrimaryColorDialogPicker> {
_selected = color; _selected = color;
}); });
}, },
),
); );
}, },
), ),
), ),
),
),
actionsPadding: const EdgeInsets.fromLTRB( actionsPadding: const EdgeInsets.fromLTRB(
Dimens.paddingL, Dimens.paddingL,
Dimens.paddingM, Dimens.paddingM,
@ -79,7 +82,7 @@ class _PrimaryColorDialogPickerState extends State<PrimaryColorDialogPicker> {
} }
} }
class _SelectableColorItem extends StatelessWidget { class _SelectableColorItem extends StatefulWidget {
final Color color; final Color color;
final bool selected; final bool selected;
final VoidCallback onTap; final VoidCallback onTap;
@ -90,19 +93,34 @@ class _SelectableColorItem extends StatelessWidget {
required this.onTap, required this.onTap,
}) : super(key: ValueKey(color)); }) : super(key: ValueKey(color));
@override
State<_SelectableColorItem> createState() => _SelectableColorItemState();
}
class _SelectableColorItemState extends State<_SelectableColorItem> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
if (widget.selected) {
Scrollable.ensureVisible(context);
}
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return GestureDetector(
onTap: onTap, onTap: widget.onTap,
child: FilledCircle( child: FilledCircle(
size: Dimens.grid48, size: Dimens.grid48,
color: color, color: widget.color,
child: AnimatedSwitcher( child: AnimatedSwitcher(
duration: Dimens.durationS, duration: Dimens.durationS,
child: selected child: widget.selected
? Icon( ? Icon(
Icons.check, Icons.check,
color: ThemeData.estimateBrightnessForColor(color) == Brightness.light color: ThemeData.estimateBrightnessForColor(widget.color) == Brightness.light
? Colors.black ? Colors.black
: Colors.white, : Colors.white,
) )