【问题标题】:How to edit the flappy_search_bar flutter package?如何编辑 flappy_search_bar 颤振包?
【发布时间】:2020-03-06 18:43:40
【问题描述】:

我想编辑flappy_search_bar的一些功能

如您所见,加载微调器是蓝色的,我似乎无法将其编辑为任何替代颜色。我也无法编辑也是蓝色的光标颜色。

这是我当前代码块的副本:

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SearchBar<Post>(
          searchBarPadding: EdgeInsets.symmetric(horizontal: 20),
          headerPadding: EdgeInsets.symmetric(horizontal: 10),
          listPadding: EdgeInsets.symmetric(horizontal: 10),
          onSearch: _getALlPosts,
          hintStyle: TextStyle(color: Colors.black87),
          hintText: 'Search',
          iconActiveColor: Colors.deepPurpleAccent,
//          cursorColor: Colors.deepPurpleAccent,
//          loader: Colors.deepPurpleAccent,
          textStyle: TextStyle(
            fontFamily: 'OpenSans',
            fontSize: 18.0,
          ),`

到目前为止,我已经尝试直接在搜索栏中进行编辑,如上图所示,添加扩展代码如下:

 class Styling extends SearchBar {
  Styling(this.cursorColor);
  final Color cursorColor;
  static const accentColor = Colors.deepPurpleAccent;

  @override
  Widget build(BuildContext context) {
    return Theme(
//      data: Theme.of(context).copyWith(
//        cursorColor: Theme.of(context).accentColor,
//      ),
        );
  }
}

我也尝试过直接编辑包文件,但这也没有成功。

有没有人建议如何编辑 flappy_search_bar 包的光标颜色和加载微调器颜色?

【问题讨论】:

    标签: flutter flutter-layout flutter-dependencies


    【解决方案1】:

    我也一直在尝试这样做并设法完成它。

    要编辑光标,请将以下内容应用于ThemeData 下的顶级 MaterialApp:

    cursorColor: Colors.red,
    cupertinoOverrideTheme: CupertinoThemeData(
        primaryColor: Colors.red,
    ),
    

    这设置了 ALL TextFields 中 Cursor 的颜色,我不知道如何仅为 flappy_search_bar 小部件中的 TextField 编辑它

    对于加载指示,将其添加到您正在使用的SearchBar 下:

    SearchBar<SomeClass>(
    ....
    loader: const Center(child: CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(Colors.red))),
    ....
    );
    

    如果您查看源代码,这就是小部件在内部执行的操作。 将Colors.red 更改为您需要的任何颜色。

    希望对您有所帮助。

    【讨论】:

    • 非常感谢您的尝试!加载器现在加载所需的颜色。我仍然无法在 SearchBar 文本字段中编辑光标。您还有其他建议吗?
    • 您是否尝试更新 MaterialApp 中 ThemeData 下的 cursorColor,如上图所示?这对我有用!
    猜你喜欢
    • 2020-11-01
    • 2021-10-08
    • 2019-07-25
    • 1970-01-01
    • 1970-01-01
    • 2022-09-27
    • 2021-04-14
    • 2020-01-16
    相关资源
    最近更新 更多