Skip to content

Commit 24f7816

Browse files
authored
Merge pull request #18 from tmaxxdd/feature/home-screen-action
Handled scroll to top and expand item
2 parents 839d9f6 + 53d6d9a commit 24f7816

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

flutter_module/lib/presentation/screens/main_screen.dart

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:flutter/gestures.dart';
21
import 'package:flutter/material.dart';
32
import 'package:flutter/rendering.dart';
43
import 'package:flutter_hooks/flutter_hooks.dart';
@@ -59,6 +58,7 @@ class _MainPage extends HookWidget {
5958
@override
6059
Widget build(BuildContext context) {
6160
useNavigator([loginNavigator, detailsNavigator]);
61+
6262
final state = useObservableState(
6363
MainModelStateData(),
6464
() => model.getState(),
@@ -72,6 +72,9 @@ class _MainPage extends HookWidget {
7272
(current, newState) => (current as MainModelEventData).equals(newState),
7373
).value;
7474

75+
final expandedState = useState(true);
76+
final controller = useScrollController();
77+
7578
useEffect(() {
7679
model.initState();
7780
}, []);
@@ -96,12 +99,19 @@ class _MainPage extends HookWidget {
9699
model: model,
97100
snippets: snippets ?? List.empty(),
98101
filter: state.filter ?? SnippetFilter(),
102+
controller: controller,
103+
expanded: expandedState.value,
104+
onExpandChange: (expanded) => expandedState.value = expanded,
99105
);
100106
},
101107
),
102108
floatingActionButton: FloatingActionButton.small(
103109
onPressed: () {
104-
// TODO Scroll to top
110+
controller.animateTo(
111+
0.0,
112+
duration: const Duration(seconds: 1),
113+
curve: const ElasticInCurve(),
114+
);
105115
},
106116
tooltip: 'Scroll to top',
107117
backgroundColor: ColorStyles.surfacePrimary(),
@@ -114,31 +124,40 @@ class _MainPage extends HookWidget {
114124
}
115125
}
116126

117-
class _MainPageData extends StatelessWidget {
118-
const _MainPageData({
119-
Key? key,
120-
required this.navigator,
121-
required this.model,
122-
required this.snippets,
123-
required this.filter,
124-
}) : super(key: key);
127+
typedef ExpandChangeListener = Function(bool);
128+
129+
class _MainPageData extends HookWidget {
130+
const _MainPageData(
131+
{Key? key,
132+
required this.navigator,
133+
required this.model,
134+
required this.snippets,
135+
required this.filter,
136+
required this.controller,
137+
required this.expanded,
138+
required this.onExpandChange})
139+
: super(key: key);
125140

126141
final DetailsNavigator navigator;
127142
final MainModelBridge model;
128143
final List<Snippet> snippets;
129144
final SnippetFilter filter;
145+
final ScrollController controller;
146+
final bool expanded;
147+
final ExpandChangeListener onExpandChange;
130148

131149
@override
132150
Widget build(BuildContext context) {
133151
return NestedScrollView(
152+
controller: controller,
134153
floatHeaderSlivers: true,
135154
headerSliverBuilder: (_, __) {
136155
return [
137156
SliverAppBar(
138157
elevation: 0.0,
139158
centerTitle: true,
140159
title: Row(mainAxisSize: MainAxisSize.min, children: [
141-
Image.asset(Assets.appLogo, width: 18.0),
160+
Image.asset(Assets.appLogo, width: Dimens.logoSignetSize),
142161
const SizedBox(width: Dimens.m),
143162
TextStyles.appBarLogo('SnipMe'),
144163
]),
@@ -150,11 +169,13 @@ class _MainPageData extends StatelessWidget {
150169
),
151170
actions: [
152171
IconButton(
153-
icon: const Icon(Icons.close_fullscreen_outlined),
172+
icon: Icon(
173+
expanded
174+
? Icons.close_fullscreen_outlined
175+
: Icons.open_in_full_outlined,
176+
),
154177
color: Colors.black,
155-
onPressed: () {
156-
// TODO Handle collapse items
157-
},
178+
onPressed: () => onExpandChange(!expanded),
158179
),
159180
],
160181
),
@@ -211,7 +232,9 @@ class _MainPageData extends StatelessWidget {
211232
},
212233
),
213234
),
214-
const SizedBox(height: Dimens.m,)
235+
const SizedBox(
236+
height: Dimens.m,
237+
)
215238
],
216239
),
217240
),
@@ -233,6 +256,7 @@ class _MainPageData extends StatelessWidget {
233256
horizontal: Dimens.m,
234257
),
235258
child: SnippetListTile(
259+
isExpanded: expanded,
236260
snippet: snippet,
237261
onTap: () {
238262
navigator.goToDetails(context, snippet.uuid!);

flutter_module/lib/presentation/styles/dimens.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ class Dimens {
99
static const filterDropdownHeight = 24.0;
1010
static const filterListHeight = 48.0;
1111
static const extendedAppBarHeight = 144.0;
12+
13+
static const logoSignetSize = 18.0;
1214
}

flutter_module/lib/presentation/widgets/snippet_list_item.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ class SnippetListTile extends HookWidget {
1313
Key? key,
1414
required this.snippet,
1515
required this.onTap,
16+
this.isExpanded = true,
1617
}) : super(key: key);
1718

18-
final bool isExpanded = true;
1919
final Snippet snippet;
2020
final GestureTapCallback? onTap;
21+
final bool isExpanded;
2122

2223
@override
2324
Widget build(BuildContext context) {

0 commit comments

Comments
 (0)