Skip to content

Commit

Permalink
Use fade transitions on Web, refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
mkobuolys committed Jan 26, 2024
1 parent 66707f0 commit 124aaa3
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 31 deletions.
4 changes: 3 additions & 1 deletion assets/markdown/composite.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ class Directory extends StatelessWidget implements IFile {
Widget render(BuildContext context) {
return Theme(
data: ThemeData(
colorScheme: ColorScheme.fromSwatch().copyWith(primary: Colors.black),
expansionTileTheme: Theme.of(context)
.expansionTileTheme
.copyWith(iconColor: Colors.black, textColor: Colors.black),
),
child: Padding(
padding: const EdgeInsets.only(left: LayoutConstants.paddingS),
Expand Down
4 changes: 3 additions & 1 deletion assets/markdown/visitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ class Directory extends StatelessWidget implements IFile {
Widget render(BuildContext context) {
return Theme(
data: ThemeData(
colorScheme: ColorScheme.fromSwatch().copyWith(primary: Colors.black),
expansionTileTheme: Theme.of(context)
.expansionTileTheme
.copyWith(iconColor: Colors.black, textColor: Colors.black),
),
child: Padding(
padding: const EdgeInsets.only(left: LayoutConstants.paddingS),
Expand Down
59 changes: 53 additions & 6 deletions lib/data/repositories/design_pattern_categories_repository.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 52 additions & 6 deletions lib/data/repositories/markdown_repository.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/design_patterns/visitor/directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class Directory extends StatelessWidget implements IFile {
Widget render(BuildContext context) {
return Theme(
data: ThemeData(
colorScheme: ColorScheme.fromSwatch().copyWith(primary: Colors.black),
expansionTileTheme: Theme.of(context)
.expansionTileTheme
.copyWith(iconColor: Colors.black, textColor: Colors.black),
),
child: Padding(
padding: const EdgeInsets.only(left: LayoutConstants.paddingS),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class _TabsLayoutState extends State<TabsLayout>
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: DetailsAppBar(designPattern: widget.designPattern),
appBar: DetailsAppBar.compact(designPattern: widget.designPattern),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _controller.index,
backgroundColor: lightBackgroundColor,
Expand Down
41 changes: 35 additions & 6 deletions lib/modules/design_pattern_details/widgets/details_app_bar.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

Expand All @@ -11,26 +13,53 @@ import '../../../widgets/logo_button.dart';
class DetailsAppBar extends StatelessWidget implements PreferredSizeWidget {
const DetailsAppBar({
required this.designPattern,
});
}) : compact = false;

const DetailsAppBar.compact({
required this.designPattern,
}) : compact = true;

final DesignPattern designPattern;
final bool compact;

void _openArticle() {
unawaited(UrlLauncher.launchUrl(designPattern.articleUrl));
}

@override
Widget build(BuildContext context) {
const color = Colors.black;

return AppBar(
automaticallyImplyLeading: false,
backgroundColor: lightBackgroundColor,
leading: !kIsWeb ? const PlatformBackButton(color: Colors.black) : null,
leading: !kIsWeb ? const PlatformBackButton(color: color) : null,
title: Text(
designPattern.title,
style: const TextStyle(color: Colors.black),
style: const TextStyle(color: color),
),
actions: [
Padding(
padding: const EdgeInsets.only(right: LayoutConstants.paddingM),
child: LogoButton(
onPressed: () => UrlLauncher.launchUrl(designPattern.articleUrl),
),
child: !compact
? TextButton.icon(
onPressed: _openArticle,
icon: Image.asset('assets/images/logo.png', width: 24.0),
label: Row(
children: [
Text(
'Read blog post',
style: Theme.of(context)
.textTheme
.bodyLarge
?.copyWith(color: color),
),
const SizedBox(width: LayoutConstants.spaceM),
const Icon(Icons.open_in_new, size: 16.0, color: color),
],
),
)
: LogoButton(onPressed: _openArticle),
),
],
);
Expand Down
39 changes: 34 additions & 5 deletions lib/navigation/router.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

Expand All @@ -20,19 +21,47 @@ GoRouter router(_) => GoRouter(
],
)
@immutable
class MainMenuRoute extends GoRouteData {
class MainMenuRoute extends GoRouteData with _CustomTransitionPageMixin {
const MainMenuRoute();

@override
Widget build(_, __) => const MainMenuPage();
Page<void> buildPage(BuildContext context, GoRouterState state) {
const child = MainMenuPage();

return buildCustomTransitionPage(context, state, child);
}
}

@immutable
class DesignPatternDetailsRoute extends GoRouteData {
class DesignPatternDetailsRoute extends GoRouteData
with _CustomTransitionPageMixin {
const DesignPatternDetailsRoute(this.id);

final String id;

@override
Widget build(_, __) => DesignPatternDetailsPage(id: id);
Page<void> buildPage(BuildContext context, GoRouterState state) {
final child = DesignPatternDetailsPage(id: id);

return buildCustomTransitionPage(context, state, child);
}
}

mixin _CustomTransitionPageMixin on GoRouteData {
Page<void> buildCustomTransitionPage(
BuildContext context,
GoRouterState state,
Widget child,
) {
if (kIsWeb) {
return CustomTransitionPage(
key: state.pageKey,
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
FadeTransition(opacity: animation, child: child),
child: child,
);
}

return MaterialPage(key: state.pageKey, child: child);
}
}
7 changes: 6 additions & 1 deletion lib/navigation/router.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion lib/widgets/design_patterns/composite/directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class Directory extends StatelessWidget implements IFile {
Widget render(BuildContext context) {
return Theme(
data: ThemeData(
colorScheme: ColorScheme.fromSwatch().copyWith(primary: Colors.black),
expansionTileTheme: Theme.of(context)
.expansionTileTheme
.copyWith(iconColor: Colors.black, textColor: Colors.black),
),
child: Padding(
padding: const EdgeInsets.only(left: LayoutConstants.paddingS),
Expand Down
3 changes: 1 addition & 2 deletions lib/widgets/logo_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class LogoButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return IconButton(
icon: Image.asset('assets/images/logo.png'),
splashRadius: 20.0,
icon: Image.asset('assets/images/logo.png', width: 24.0),
onPressed: onPressed,
);
}
Expand Down

0 comments on commit 124aaa3

Please sign in to comment.