Skip to content

Commit

Permalink
resolve navigate to footer todos
Browse files Browse the repository at this point in the history
  • Loading branch information
akaiser committed Nov 27, 2023
1 parent 243d2bf commit a234c5a
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 56 deletions.
4 changes: 2 additions & 2 deletions integration_test/pages/design_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:raumunikate/pages/nav_bar/_data.dart';

import '../test_helper.dart';

const _sectionTypes = [
const _sectionTypes = {
DesignIntroSection,
DesignPhasesPartOneSection,
DesignPhasesPartTwoSection,
Expand All @@ -23,7 +23,7 @@ const _sectionTypes = [
DesignNaturalFullSection,
DesignElegantFullSection,
Footer,
];
};

void main() {
testWidgets('ensures to be on $DesignPage', (tester) async {
Expand Down
53 changes: 37 additions & 16 deletions integration_test/pages/home_page_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:raumunikate/pages/_footer/footer.dart';
import 'package:raumunikate/pages/a/a/home_intro_section.dart';
import 'package:raumunikate/pages/a/b/_data.dart' as home_welcome_data;
import 'package:raumunikate/pages/a/b/home_welcome_sections.dart';
import 'package:raumunikate/pages/a/c/home_content_section.dart';
import 'package:raumunikate/pages/a/d/home_image_section.dart';
Expand All @@ -11,14 +11,14 @@ import 'package:raumunikate/pages/nav_bar/_data.dart';

import '../test_helper.dart';

const _sectionTypes = [
const _sectionTypes = {
HomeIntroSection,
HomeWelcomeSection,
HomeContentSection,
HomeImageSection,
HomeReferralsSection,
Footer,
];
};

void main() {
testWidgets('ensures to be on $HomePage', (tester) async {
Expand All @@ -32,26 +32,47 @@ void main() {
expect(find.byType(HomePage), findsOneWidget);
});

testWidgets('cycles through all sections and slides', (tester) async {
testWidgets('cycles through all sections of $HomePage', (tester) async {
await tester.pumpApp();

tester.expectType(HomeIntroSection, _sectionTypes);

await tester.dragPageView();
tester.expectType(HomeWelcomeSection, _sectionTypes);
for (final sectionType in _sectionTypes) {
if (_sectionTypes.first != sectionType) {
await tester.dragPageView();
}
tester.expectType(sectionType, _sectionTypes);
}
});

await tester.dragPageView();
tester.expectType(HomeContentSection, _sectionTypes);
expect(find.byKey(const Key('home-content-slide-card-0')), findsOneWidget);
// TODO(albert): finish this...
// TODO(albert): finish this...
// testWidgets('cycles through all sections and slides', (tester) async {
// await tester.pumpApp();
//
// tester.expectType(HomeIntroSection, _sectionTypes);
//
// await tester.dragPageView();
// tester.expectType(HomeWelcomeSection, _sectionTypes);
//
// await tester.dragPageView();
// tester.expectType(HomeContentSection, _sectionTypes);
// expect(find.byKey(const Key('home-content-slide-card-0')), findsOneWidget);
//
// await tester.dragPageView();
// tester.expectType(HomeImageSection, _sectionTypes);
//
// await tester.dragPageView();
// tester.expectType(HomeReferralsSection, _sectionTypes);
//
// await tester.dragPageView();
// tester.expectType(Footer, _sectionTypes);
// });

testWidgets('contact tap slides down to footer section', (tester) async {
await tester.pumpApp();
await tester.dragPageView();
tester.expectType(HomeImageSection, _sectionTypes);

await tester.dragPageView();
tester.expectType(HomeReferralsSection, _sectionTypes);
await tester.tap(find.text(home_welcome_data.cta));
await tester.pumpAndSettle();

await tester.dragPageView();
tester.expectType(Footer, _sectionTypes);
});
}
15 changes: 13 additions & 2 deletions integration_test/pages/portrait_page_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:raumunikate/pages/_footer/footer.dart';
import 'package:raumunikate/pages/e/a/portrait_intro_section.dart';
import 'package:raumunikate/pages/e/b/_data.dart' as portrait_about_data;
import 'package:raumunikate/pages/e/b/portrait_about_sections.dart';
import 'package:raumunikate/pages/e/c/portrait_product_sections.dart';
import 'package:raumunikate/pages/e/d/portrait_blog_sections.dart';
Expand All @@ -9,13 +10,13 @@ import 'package:raumunikate/pages/nav_bar/_data.dart';

import '../test_helper.dart';

const _sectionTypes = [
const _sectionTypes = {
PortraitIntroSection,
PortraitAboutSection,
PortraitProductSection,
PortraitBlogSection,
Footer,
];
};

void main() {
testWidgets('ensures to be on $PortraitPage', (tester) async {
Expand All @@ -39,4 +40,14 @@ void main() {
tester.expectType(sectionType, _sectionTypes);
}
});

testWidgets('contact tap slides down to footer section', (tester) async {
await tester.pumpApp();
await tester.dragPageView();

await tester.tap(find.text(portrait_about_data.cta));
await tester.pumpAndSettle();

tester.expectType(Footer, _sectionTypes);
});
}
4 changes: 2 additions & 2 deletions integration_test/pages/products_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import 'package:raumunikate/pages/nav_bar/_data.dart';

import '../test_helper.dart';

const _sectionTypes = [
const _sectionTypes = {
ProductsIntroSection,
ProductsAboutSection,
ProductsTypeSlides,
ProductsShapeSection,
ProductsCitationSection,
Footer,
];
};

void main() {
testWidgets('ensures to be on $ProductsPage', (tester) async {
Expand Down
4 changes: 2 additions & 2 deletions integration_test/pages/projects_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import 'package:raumunikate/pages/nav_bar/_data.dart';

import '../test_helper.dart';

const _sectionTypes = [
const _sectionTypes = {
ProjectsIntroSection,
ProjectsWolfSection,
ProjectsWolfHowSection,
ProjectsTheuerSection,
ProjectsTheuerHowSection,
Footer,
];
};

void main() {
testWidgets('ensures to be on $ProjectsPage', (tester) async {
Expand Down
2 changes: 1 addition & 1 deletion integration_test/test_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension WidgetTesterExt on WidgetTester {
await pumpAndSettle();
}

void expectType(Type type, List<Type> types) {
void expectType(Type type, Iterable<Type> types) {
for (final _type in types) {
expect(
find.byType(_type),
Expand Down
3 changes: 1 addition & 2 deletions lib/_environment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ abstract final class Environment {
static const _prodEnv = '';
static const _devEnv = '/own/raumunikate.com';

static late final String basePath;
static late final String contactPath;

static void init() {
basePath = kProfileMode ? _devEnv : _prodEnv;
const basePath = kProfileMode ? _devEnv : _prodEnv;
contactPath = '$basePath/contact.php';
}
}
18 changes: 16 additions & 2 deletions lib/_notifier.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:provider/provider.dart';

export 'package:provider/provider.dart';

class NavBarNotifier with ChangeNotifier {
bool isExpanded = true;

void get toggle {
void toggle() {
isExpanded = !isExpanded;
notifyListeners();
}
}

class ScrollToBottomNotifier with ChangeNotifier {
void notify() => notifyListeners();
}

extension BuildContextExt on BuildContext {
NavBarNotifier get navBarNotifier => read<NavBarNotifier>();

ScrollToBottomNotifier get scrollToBottomNotifier =>
read<ScrollToBottomNotifier>();
}
8 changes: 5 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async' show runZonedGuarded;
import 'dart:developer' show log;

import 'package:provider/provider.dart';
import 'package:raumunikate/_environment.dart';
import 'package:raumunikate/_notifier.dart';
import 'package:raumunikate/_router.dart';
Expand All @@ -25,8 +24,11 @@ class App extends StatelessWidget {
const App({super.key});

@override
Widget build(BuildContext context) => ChangeNotifierProvider(
create: (_) => NavBarNotifier(),
Widget build(BuildContext context) => MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => NavBarNotifier()),
ChangeNotifierProvider(create: (_) => ScrollToBottomNotifier()),
],
child: MaterialApp.router(
debugShowCheckedModeBanner: false,
theme: theme,
Expand Down
9 changes: 4 additions & 5 deletions lib/pages/_base_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import 'package:raumunikate/_images.dart';
import 'package:raumunikate/_notifier.dart';
import 'package:raumunikate/_routes.dart';
Expand Down Expand Up @@ -38,9 +37,9 @@ class _BasePageState extends State<BasePage> {
WidgetsBinding.instance.addPostFrameCallback(
(_) {
// When navigating to new scaffold and NavBar was not expanded yet...
final navBarNotifier = context.read<NavBarNotifier>();
final navBarNotifier = context.navBarNotifier;
if (!navBarNotifier.isExpanded) {
navBarNotifier.toggle;
navBarNotifier.toggle();
}
},
);
Expand All @@ -66,7 +65,7 @@ class _BasePageState extends State<BasePage> {
@override
Widget build(BuildContext context) {
final screenSize = context.screenSize;
final navBarNotifier = context.read<NavBarNotifier>();
final navBarNotifier = context.navBarNotifier;
return Scaffold(
body: DefaultTextStyle.merge(
style: context.tt.body?.copyWith(color: raumGrau),
Expand All @@ -79,7 +78,7 @@ class _BasePageState extends State<BasePage> {
if (notification.metrics.axis == Axis.vertical) {
final isAtTop = notification.metrics.pixels <= 10;
if (navBarNotifier.isExpanded != isAtTop) {
navBarNotifier.toggle;
navBarNotifier.toggle();
}
}
return true;
Expand Down
5 changes: 2 additions & 3 deletions lib/pages/a/b/_home_welcome_text.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:raumunikate/_notifier.dart';
import 'package:raumunikate/pages/_shared/components/full_text_section.dart';
import 'package:raumunikate/pages/_shared/ui/action_button.dart';
import 'package:raumunikate/pages/a/b/_data.dart' as data;
Expand All @@ -13,9 +14,7 @@ class HomeWelcomeText extends StatelessWidget {
text: data.content,
actionButton: ActionButton(
data.cta,
onTap: () {
// TODO(albert): where to go?
},
onTap: () => context.scrollToBottomNotifier.notify(),
),
);
}
23 changes: 17 additions & 6 deletions lib/pages/base_slide_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:raumunikate/_notifier.dart';
import 'package:raumunikate/_settings.dart';
import 'package:raumunikate/pages/_base_page.dart';
import 'package:raumunikate/pages/_footer/footer.dart';
Expand All @@ -17,26 +18,36 @@ class BaseSlidePage extends StatefulWidget {

class _BaseSlidePageState extends State<BaseSlidePage> {
late final PageController _controller;
late final ScrollToBottomNotifier _scrollToBottomNotifier;

@override
void initState() {
super.initState();
_controller = PageController();
_scrollToBottomNotifier = context.scrollToBottomNotifier
..addListener(_scrollToBottom);
}

@override
void dispose() {
_controller.dispose();
_scrollToBottomNotifier.removeListener(_scrollToBottom);
super.dispose();
}

void get _scrollToTop => _controller.animateToPage(
void _scrollToTop() => _controller.animateToPage(
0,
duration: const Duration(milliseconds: pageTransitionInMillis),
curve: Curves.ease,
);

void get _onScrollUpRequest {
void _scrollToBottom() => _controller.animateToPage(
widget.children.length,
duration: const Duration(milliseconds: pageTransitionInMillis),
curve: Curves.ease,
);

void _onScrollUpRequest() {
if (widget.children.length != _controller.page?.toInt()) {
_controller.nextPage(
duration: const Duration(milliseconds: pageTransitionInMillis),
Expand All @@ -45,7 +56,7 @@ class _BaseSlidePageState extends State<BaseSlidePage> {
}
}

void get _onScrollDownRequest {
void _onScrollDownRequest() {
if (_controller.page?.toInt() != 0) {
_controller.previousPage(
duration: const Duration(milliseconds: pageTransitionInMillis),
Expand All @@ -58,9 +69,9 @@ class _BaseSlidePageState extends State<BaseSlidePage> {
Widget build(BuildContext context) {
final _children = [...widget.children, const _Footer()];
return BasePage(
onScrollToTopTap: () => _scrollToTop,
onScrollUpRequest: () => _onScrollUpRequest,
onScrollDownRequest: () => _onScrollDownRequest,
onScrollToTopTap: _scrollToTop,
onScrollUpRequest: _onScrollUpRequest,
onScrollDownRequest: _onScrollDownRequest,
child: PageView.builder(
key: baseSlidePageKey,
controller: _controller,
Expand Down
5 changes: 2 additions & 3 deletions lib/pages/d/b/_products_about_text.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:raumunikate/_notifier.dart';
import 'package:raumunikate/pages/_shared/components/full_text_section.dart';
import 'package:raumunikate/pages/_shared/ui/action_button.dart';
import 'package:raumunikate/pages/d/b/_data.dart' as data;
Expand All @@ -13,9 +14,7 @@ class ProductsAboutText extends StatelessWidget {
text: data.content,
actionButton: ActionButton(
data.cta,
onTap: () {
// TODO(albert): where to go?
},
onTap: () => context.scrollToBottomNotifier.notify(),
),
);
}
Loading

0 comments on commit a234c5a

Please sign in to comment.