Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 40 additions & 16 deletions flutter_module/lib/presentation/screens/main_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
Expand Down Expand Up @@ -59,6 +58,7 @@ class _MainPage extends HookWidget {
@override
Widget build(BuildContext context) {
useNavigator([loginNavigator, detailsNavigator]);

final state = useObservableState(
MainModelStateData(),
() => model.getState(),
Expand All @@ -72,6 +72,9 @@ class _MainPage extends HookWidget {
(current, newState) => (current as MainModelEventData).equals(newState),
).value;

final expandedState = useState(true);
final controller = useScrollController();

useEffect(() {
model.initState();
}, []);
Expand All @@ -96,12 +99,19 @@ class _MainPage extends HookWidget {
model: model,
snippets: snippets ?? List.empty(),
filter: state.filter ?? SnippetFilter(),
controller: controller,
expanded: expandedState.value,
onExpandChange: (expanded) => expandedState.value = expanded,
);
},
),
floatingActionButton: FloatingActionButton.small(
onPressed: () {
// TODO Scroll to top
controller.animateTo(
0.0,
duration: const Duration(seconds: 1),
curve: const ElasticInCurve(),
);
},
tooltip: 'Scroll to top',
backgroundColor: ColorStyles.surfacePrimary(),
Expand All @@ -114,31 +124,40 @@ class _MainPage extends HookWidget {
}
}

class _MainPageData extends StatelessWidget {
const _MainPageData({
Key? key,
required this.navigator,
required this.model,
required this.snippets,
required this.filter,
}) : super(key: key);
typedef ExpandChangeListener = Function(bool);

class _MainPageData extends HookWidget {
const _MainPageData(
{Key? key,
required this.navigator,
required this.model,
required this.snippets,
required this.filter,
required this.controller,
required this.expanded,
required this.onExpandChange})
: super(key: key);

final DetailsNavigator navigator;
final MainModelBridge model;
final List<Snippet> snippets;
final SnippetFilter filter;
final ScrollController controller;
final bool expanded;
final ExpandChangeListener onExpandChange;

@override
Widget build(BuildContext context) {
return NestedScrollView(
controller: controller,
floatHeaderSlivers: true,
headerSliverBuilder: (_, __) {
return [
SliverAppBar(
elevation: 0.0,
centerTitle: true,
title: Row(mainAxisSize: MainAxisSize.min, children: [
Image.asset(Assets.appLogo, width: 18.0),
Image.asset(Assets.appLogo, width: Dimens.logoSignetSize),
const SizedBox(width: Dimens.m),
TextStyles.appBarLogo('SnipMe'),
]),
Expand All @@ -150,11 +169,13 @@ class _MainPageData extends StatelessWidget {
),
actions: [
IconButton(
icon: const Icon(Icons.close_fullscreen_outlined),
icon: Icon(
expanded
? Icons.close_fullscreen_outlined
: Icons.open_in_full_outlined,
),
color: Colors.black,
onPressed: () {
// TODO Handle collapse items
},
onPressed: () => onExpandChange(!expanded),
),
],
),
Expand Down Expand Up @@ -211,7 +232,9 @@ class _MainPageData extends StatelessWidget {
},
),
),
const SizedBox(height: Dimens.m,)
const SizedBox(
height: Dimens.m,
)
],
),
),
Expand All @@ -233,6 +256,7 @@ class _MainPageData extends StatelessWidget {
horizontal: Dimens.m,
),
child: SnippetListTile(
isExpanded: expanded,
snippet: snippet,
onTap: () {
navigator.goToDetails(context, snippet.uuid!);
Expand Down
2 changes: 2 additions & 0 deletions flutter_module/lib/presentation/styles/dimens.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ class Dimens {
static const filterDropdownHeight = 24.0;
static const filterListHeight = 48.0;
static const extendedAppBarHeight = 144.0;

static const logoSignetSize = 18.0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ class SnippetListTile extends HookWidget {
Key? key,
required this.snippet,
required this.onTap,
this.isExpanded = true,
}) : super(key: key);

final bool isExpanded = true;
final Snippet snippet;
final GestureTapCallback? onTap;
final bool isExpanded;

@override
Widget build(BuildContext context) {
Expand Down