Я пытаюсь вписаться в функцию построения панели поиска вместо заголовка. Он прекрасно работает как часть тела appBar. Вот реализация buildSearchBar, которую я хочу разместить внутри AppBar:
buildSearchBar(BuildContext context) {
return SliverPadding(
padding: EdgeInsets.only(left: 16.0, right: 16.0, top: 16.0),
sliver: SliverList(
delegate: SliverChildListDelegate([
Card(
color: Colors.transparent,
elevation: 8,
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(16.0)),
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16.0),
color: Theme.of(context).accentColor,
child: TextField(
decoration: InputDecoration(
icon: Icon(Icons.search),
border: InputBorder.none,
hintStyle:
TextStyle(fontSize: 18, color: Colors.black54),
hintText: 'Search news'),
textInputAction: TextInputAction.search,
cursorColor: Colors.black54,
style: TextStyle(fontSize: 18, color: Colors.black54),
controller: TextEditingController(),
onSubmitted: (text) => searchLogic(context, text),
),
)))
]),
),
);
}
Вот как я подошел к созданию AppBar
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: buildSearchBar(context),
backgroundColor: Theme.of(context).brightness == Brightness.dark
? Colors.grey[850]
: Theme.of(context).accentColor,
),
body: CustomScrollView(
controller: scrollControllerSearchPage,
slivers: <Widget>[
SliverToBoxAdapter(
),
buildSearchBar(context),
],
),
);
}
Я попытался создать столбец и разместить его внутри SizedBox, но получил следующие исключения:
flutter: Another exception was thrown: A _RenderAppBarTitleBox expected a child of type RenderBox but received a child of type RenderSliverPadding.
flutter: Another exception was thrown: NoSuchMethodError: The method 'layout' was called on null.
flutter: Another exception was thrown: RenderBox was not laid out: _RenderAppBarTitleBox#9675d relayoutBoundary=up16 NEEDS-PAINT
flutter: Another exception was thrown: RenderBox was not laid out: RenderSemanticsAnnotations#51f2d relayoutBoundary=up15 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter: Another exception was thrown: Updated layout information required for RenderErrorBox#742c7 NEEDS-LAYOUT NEEDS-PAINT to calculate semantics.