Skip to content

Commit 9b46b6a

Browse files
committed
Merge branch 'main' of https://github.com/michalsrutek/draggable_home into michalsrutek-main
2 parents 309d602 + d84519b commit 9b46b6a

File tree

1 file changed

+42
-46
lines changed

1 file changed

+42
-46
lines changed

lib/draggable_home.dart

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -179,54 +179,49 @@ class _DraggableHomeState extends State<DraggableHome> {
179179
double topPadding,
180180
) {
181181
return CustomScrollView(
182-
physics: BouncingScrollPhysics(),
182+
physics: const BouncingScrollPhysics(),
183183
slivers: [
184184
StreamBuilder<List<bool>>(
185185
stream: CombineLatestStream.list<bool>(
186186
[isFullyCollapsed.stream, isFullyExpanded.stream]),
187187
builder: (BuildContext context, AsyncSnapshot<List<bool>> snapshot) {
188-
List<bool> streams = (snapshot.data ?? [false, false]);
188+
final List<bool> streams = (snapshot.data ?? [false, false]);
189+
final bool fullyCollapsed = streams[0];
190+
final bool fullyExpanded = streams[1];
189191

190192
return SliverAppBar(
191193
leading: widget.alwaysShowLeadingAndAction
192194
? widget.leading
193-
: !streams[0]
194-
? SizedBox()
195+
: !fullyCollapsed
196+
? const SizedBox()
195197
: widget.leading,
196198
actions: widget.alwaysShowLeadingAndAction
197199
? widget.actions
198-
: !streams[0]
200+
: !fullyCollapsed
199201
? []
200202
: widget.actions,
201203
elevation: 0,
202204
pinned: true,
203205
stretch: true,
204206
centerTitle: widget.centerTitle,
205-
title: StreamBuilder<bool>(
206-
stream: null,
207-
builder: (context, snapshot) {
208-
if (widget.alwaysShowTitle) {
209-
return widget.title;
210-
} else {
211-
return AnimatedOpacity(
212-
opacity: streams[0] ? 1 : 0,
213-
duration: Duration(milliseconds: 100),
207+
title: widget.alwaysShowTitle
208+
? widget.title
209+
: AnimatedOpacity(
210+
opacity: fullyCollapsed ? 1 : 0,
211+
duration: const Duration(milliseconds: 100),
214212
child: widget.title,
215-
);
216-
}
217-
},
218-
),
213+
),
219214
collapsedHeight: appBarHeight,
220-
expandedHeight: streams[1] ? fullyExpandedHeight : expandedHeight,
215+
expandedHeight:
216+
fullyExpanded ? fullyExpandedHeight : expandedHeight,
221217
flexibleSpace: Stack(
222218
children: [
223219
FlexibleSpaceBar(
224220
background: Container(
225-
child: streams[1]
226-
? (widget.expandedBody == null
227-
? Container()
228-
: widget.expandedBody)
229-
: widget.headerWidget),
221+
child: fullyExpanded
222+
? (widget.expandedBody ?? const SizedBox())
223+
: widget.headerWidget,
224+
),
230225
),
231226
Positioned(
232227
bottom: -1,
@@ -237,19 +232,19 @@ class _DraggableHomeState extends State<DraggableHome> {
237232
Positioned(
238233
bottom: 0 + widget.curvedBodyRadius,
239234
child: AnimatedContainer(
240-
padding: EdgeInsets.only(left: 10, right: 10),
235+
padding: const EdgeInsets.only(left: 10, right: 10),
241236
curve: Curves.easeInOutCirc,
242-
duration: Duration(milliseconds: 100),
243-
height: streams[0]
237+
duration: const Duration(milliseconds: 100),
238+
height: fullyCollapsed
244239
? 0
245-
: streams[1]
240+
: fullyExpanded
246241
? 0
247242
: kToolbarHeight,
248243
width: MediaQuery.of(context).size.width,
249-
child: streams[0]
250-
? SizedBox()
251-
: streams[1]
252-
? SizedBox()
244+
child: fullyCollapsed
245+
? const SizedBox()
246+
: fullyExpanded
247+
? const SizedBox()
253248
: widget.headerBottomBar ?? Container(),
254249
),
255250
)
@@ -258,7 +253,7 @@ class _DraggableHomeState extends State<DraggableHome> {
258253
stretchTriggerOffset: widget.stretchTriggerOffset,
259254
onStretchTrigger: widget.fullyStretchable
260255
? () async {
261-
if (streams[1] == false) isFullyExpanded.add(true);
256+
if (!fullyExpanded) isFullyExpanded.add(true);
262257
}
263258
: null,
264259
);
@@ -313,19 +308,20 @@ class _DraggableHomeState extends State<DraggableHome> {
313308

314309
StreamBuilder<bool> expandedUpArrow() {
315310
return StreamBuilder<bool>(
316-
stream: isFullyExpanded.stream,
317-
builder: (context, snapshot) {
318-
return AnimatedContainer(
319-
duration: Duration(milliseconds: 500),
320-
height: (snapshot.data ?? false) ? 25 : 0,
321-
width: MediaQuery.of(context).size.width,
322-
child: Center(
323-
child: Icon(
324-
Icons.keyboard_arrow_up_rounded,
325-
color: (snapshot.data ?? false) ? null : Colors.transparent,
326-
),
311+
stream: isFullyExpanded.stream,
312+
builder: (context, snapshot) {
313+
return AnimatedContainer(
314+
duration: const Duration(milliseconds: 500),
315+
height: (snapshot.data ?? false) ? 25 : 0,
316+
width: MediaQuery.of(context).size.width,
317+
child: Center(
318+
child: Icon(
319+
Icons.keyboard_arrow_up_rounded,
320+
color: (snapshot.data ?? false) ? null : Colors.transparent,
327321
),
328-
);
329-
});
322+
),
323+
);
324+
},
325+
);
330326
}
331327
}

0 commit comments

Comments
 (0)