Skip to content

Commit

Permalink
Merge pull request #16 from mkobuolys/fix/slide-steps-listener-and-bu…
Browse files Browse the repository at this point in the history
…ilder

fix: unnecessary steps builder and listener triggers
  • Loading branch information
mkobuolys authored Sep 22, 2023
2 parents cf6ad5f + 3a23c16 commit f6b1d3f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/add_presentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Add information about the presentation here.

**Requirements**

- [ ] Provide a link to the presentation (if deployed, just to check it out)
- [ ] Provide a link to the source code
- [ ] Provide a title for the presentation
- [ ] Provide a language of the presentation
- [ ] Provide your full name
- [ ] Provide a link to your social media profile
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# NEXT

- fix: `FlutterDeckSlideStepsBuilder` triggers builder on slide change
- fix: `FlutterDeckSlideStepsListener` triggers listener on slide change

# 0.4.2

docs: update split slide documentation in README.md
- docs: update split slide documentation in README.md

# 0.4.1

fix: override text colors for Material text styles
- fix: override text colors for Material text styles

# 0.4.0

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,11 @@ Every slide deck comes with a navigation drawer that can be used to navigate thr

## Presentations built with flutter_deck 🚀

| Title | Author |
| ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------- |
| [Let me introduce you to Flutter](https://github.com/mkobuolys/introduction-to-flutter) | [Mangirdas Kazlauskas][mangirdas_kazlauskas_link] |
| [Control your Flutter application on the fly with Firebase Remote Config](https://github.com/mkobuolys/firebase-remote-config-talk) | [Mangirdas Kazlauskas][mangirdas_kazlauskas_link] |
| [Introdução ao Flutter Web (Introduction to Flutter Web)](https://github.com/afucher/flutter_web_101) | [Arthur Fücher](https://x.com/Thur) |
| Title | Language | Author |
| ----------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------------------------------------------- |
| [Let me introduce you to Flutter](https://github.com/mkobuolys/introduction-to-flutter) | English | [Mangirdas Kazlauskas][mangirdas_kazlauskas_link] |
| [Control your Flutter application on the fly with Firebase Remote Config](https://github.com/mkobuolys/firebase-remote-config-talk) | English | [Mangirdas Kazlauskas][mangirdas_kazlauskas_link] |
| [Introduction to Flutter Web](https://github.com/afucher/flutter_web_101) | Portuguese | [Arthur Fücher](https://x.com/Thur) |

[flutter_install_link]: https://docs.flutter.dev/get-started/install
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
Expand Down
4 changes: 3 additions & 1 deletion cspell/authors.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Mangirdas
Kazlauskas
Kazlauskas
Arthur
Fücher
12 changes: 10 additions & 2 deletions lib/src/widgets/flutter_deck_slide_steps_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class _FlutterDeckSlideStepsBuilderState
extends State<FlutterDeckSlideStepsBuilder> {
FlutterDeckRouter? _router;
int? _stepNumber;
int? _slideNumber;

@override
void dispose() {
Expand All @@ -50,15 +51,22 @@ class _FlutterDeckSlideStepsBuilderState

if (_router != null) return;

_router = context.flutterDeck.router..addListener(_onRouteChange);
final flutterDeck = context.flutterDeck;

_slideNumber = flutterDeck.slideNumber;
_router = flutterDeck.router..addListener(_onRouteChange);

// Needed for the first render, e.g. when the user navigates to a slide
// directly via URL or deep link.
_onRouteChange();
}

void _onRouteChange() {
setState(() => _stepNumber = context.flutterDeck.stepNumber);
final flutterDeck = context.flutterDeck;

if (_slideNumber != flutterDeck.slideNumber) return;

setState(() => _stepNumber = flutterDeck.stepNumber);
}

@override
Expand Down
12 changes: 10 additions & 2 deletions lib/src/widgets/flutter_deck_slide_steps_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class FlutterDeckSlideStepsListener extends StatefulWidget {
class _FlutterDeckSlideStepsListenerState
extends State<FlutterDeckSlideStepsListener> {
FlutterDeckRouter? _router;
int? _slideNumber;

@override
void dispose() {
Expand All @@ -53,11 +54,18 @@ class _FlutterDeckSlideStepsListenerState

if (_router != null) return;

_router = context.flutterDeck.router..addListener(_onRouteChange);
final flutterDeck = context.flutterDeck;

_slideNumber = flutterDeck.slideNumber;
_router = flutterDeck.router..addListener(_onRouteChange);
}

void _onRouteChange() {
widget.listener(context, context.flutterDeck.stepNumber);
final flutterDeck = context.flutterDeck;

if (_slideNumber != flutterDeck.slideNumber) return;

widget.listener(context, flutterDeck.stepNumber);
}

@override
Expand Down

0 comments on commit f6b1d3f

Please sign in to comment.