如何在Flutter中自定义数字选择器? [英] How to customize numberpicker in Flutter?

查看:623
本文介绍了如何在Flutter中自定义数字选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中实现了数字选择器
我想修改数字的大小以及突出显示的值和未突出显示的值的颜色。我设法修改了突出显示的内容,将其包装在主题小部件中并修改了accentcolor,但是不知道如何进行其他自定义?

I implemented numberpicker in my app. I would like to modify the size of the numbers and the color of both highlighted value and those who are not. I managed to modify the highlighted ones wrapping it in the Theme widget and modifing the accentcolor, but don't know how I can do the other customizations?

Theme(
  data: Theme.of(context).copyWith(
    accentColor: Colors.red,
  ),
  child: NumberPicker.integer(
    initialValue: _currentPickerValue,
    minValue: 0,
    maxValue: 100,
    onChanged: (newValue) =>
      setState(() => _currentPickerValue = newValue))) 


推荐答案

我深入了代码,这是我发现

I digged into the code and here is something that I found


  • selectedStyle = themeData.textTheme.headline.copyWith(color:themeData.accentColor);

defaultStyle = themeData.textTheme.body1; 此是未突出显示的

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

to change the size or color or any other style attribute modifiy those style.

下面是示例代码:

final theme = Theme.of(context);
Theme(
      data: theme.copyWith(
        accentColor: Colors.black,// highlted color
          textTheme: theme.textTheme.copyWith(
            headline5: theme.textTheme.headline5.copyWith(..), //other highlighted style
            bodyText2: theme.textTheme.headline5.copyWith(...), //not highlighted styles
      )),
      child: NumberPicker.integer(...),
    ); 

这篇关于如何在Flutter中自定义数字选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆