ArcticZeroo / flutter-search-bar

(mostly) Automatic search-enabled appBar for flutter
BSD 3-Clause "New" or "Revised" License
266 stars 69 forks source link

Theming support #21

Closed mk-dev-1 closed 4 years ago

mk-dev-1 commented 6 years ago

Hi guys,

overall, the search bar is great and works perfectly. However, i'm starting to run into trouble when I try theming the bar, specifically the hint color or the button colors. The issue seems to be related to the below part:

Color textColor = inBar ? Colors.white70 : Colors.black54;

return new AppBar(
  leading: new BackButton(
    color: buttonColor
  ),
  backgroundColor: barColor,
  title: new Directionality(
    textDirection: Directionality.of(context),
    child: new TextField(
      key: new Key('SearchBarTextField'),
      keyboardType: TextInputType.text,
      style: new TextStyle(
          color: textColor,
          fontSize: 16.0
      ),
      decoration: new InputDecoration(
          hintText: hintText,
          hintStyle: new TextStyle(
              color: textColor,
              fontSize: 16.0
          ),
          border: null
      ),

TextColor is only depending on the search bar type (inBar), and has no relation to the Theme used...

Would it be possible to give some more flexibility for coloring the searchbar?

Would be highly appreciated!

Thanks, Matthias

ArcticZeroo commented 6 years ago

Yeah, I think this makes sense to add. An ideal implementation imo would be to either convert this search bar to a StatefulWidget (which is more ideal for reasons related to the fact that this is how flutter is generally structured, but also introduces some concerns) which would allow it to be wrapped in a Theme, or to allow an entire ThemeData to be passed as a param. I'd personally prefer to convert it to a widget, but this would be a breaking change.