如何在Flutter中自定义numberpicker?

问题描述 投票:0回答:1

我在我的应用程序中实现了numberpicker。我想修改数字的大小和突出显示的值的颜色和不突出显示的颜色。我设法修改了在主题窗口小部件中包含它的突出显示的内容并修改了重音颜色,但是我不知道如何进行其他自定义?

Theme(
  data: Theme.of(context).copyWith(
    accentColor: Colors.red,
  ),
  child: NumberPicker.integer(
    initialValue: _currentPickerValue,
    minValue: 0,
    maxValue: 100,
    onChanged: (newValue) =>
      setState(() => _currentPickerValue = newValue))) 
dart flutter
1个回答
1
投票

我深入研究了代码,这是我发现的东西

  • selectedStyle = themeData.textTheme.headline.copyWith(color: themeData.accentColor);
  • defaultStyle = themeData.textTheme.body1;这是没有突出显示的

更改大小或颜色或任何其他样式属性修改样式。

这是一个示例代码:

final theme = Theme.of(context);
Theme(
      data: theme.copyWith(
        accentColor: Colors.black,// highlted color
          textTheme: theme.textTheme.copyWith(
            headline: theme.textTheme.headline.copyWith(..), //other highlighted style
            body1: theme.textTheme.headline.copyWith(...), //not highlighted styles
      )),
      child: NumberPicker.integer(...),
    ); 
© www.soinside.com 2019 - 2024. All rights reserved.