-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add flutter_deck_client package
- Loading branch information
Showing
9 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 0.1.0 | ||
|
||
- feat: add flutter_deck_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Mangirdas Kazlauskas | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# flutter_deck_client | ||
|
||
A common client interface and models for the [flutter_deck](https://pub.dev/packages/flutter_deck) package. | ||
|
||
## Usage | ||
|
||
To implement a new client for [flutter_deck](https://pub.dev/packages/flutter_deck), implement [FlutterDeckClient](https://github.com/mkobuolys/flutter_deck/tree/main/packages/flutter_deck_client/lib/src/flutter_deck_client.dart) interface with your own logic: | ||
|
||
```dart | ||
class MyFlutterDeckClient implements FlutterDeckClient { | ||
const MyFlutterDeckClient(); | ||
@override | ||
Stream<FlutterDeckState> get flutterDeckStateStream { <...> } | ||
@override | ||
void init([FlutterDeckState? state]) { <...> } | ||
@override | ||
void dispose() { <...> } | ||
@override | ||
void updateState(FlutterDeckState state) { <...> } | ||
} | ||
``` | ||
|
||
## Note on breaking changes | ||
|
||
Strongly prefer non-breaking changes (such as adding a method to the interface) over breaking changes for this package. | ||
|
||
See https://flutter.dev/go/platform-interface-breaking-changes for a discussion on why a less-clean interface is preferable to a breaking change. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include: ../../analysis_options.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// A common client interface and models for the flutter_deck package. | ||
library flutter_deck_client; | ||
|
||
export 'src/flutter_deck_client.dart'; | ||
export 'src/models/models.dart'; |
31 changes: 31 additions & 0 deletions
31
packages/flutter_deck_client/lib/src/flutter_deck_client.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:flutter_deck_client/src/models/models.dart'; | ||
|
||
/// A common client interface for the flutter_deck package. | ||
/// | ||
/// To implement a custom client, implement this interface and use it in your | ||
/// flutter_deck presentation. | ||
abstract interface class FlutterDeckClient { | ||
/// Initializes the client with the given [state]. | ||
/// | ||
/// In flutter_deck, the presentation will call this method with the initial | ||
/// state of the presentation. The presenter view will also call this method, | ||
/// but with a null state. | ||
void init([FlutterDeckState? state]); | ||
|
||
/// Disposes the client. | ||
/// | ||
/// This method should be called when the client is no longer needed. | ||
void dispose(); | ||
|
||
/// Updates the client state with the given [state]. | ||
/// | ||
/// This method is called by both the presentation and the presenter view to | ||
/// keep the [FlutterDeckState] in sync. | ||
void updateState(FlutterDeckState state); | ||
|
||
/// Returns the state as a stream of [FlutterDeckState] objects. | ||
/// | ||
/// This stream is used by flutter_deck framework to keep the presentation and | ||
/// the presenter view in sync. | ||
Stream<FlutterDeckState> get flutterDeckStateStream; | ||
} |
94 changes: 94 additions & 0 deletions
94
packages/flutter_deck_client/lib/src/models/flutter_deck_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import 'package:meta/meta.dart'; | ||
|
||
/// Represents the state of a flutter_deck presentation. | ||
/// | ||
/// This class is a single source of truth for the state of a flutter_deck | ||
/// presentation. It is used by both the presentation and the presenter view to | ||
/// keep the state in sync. | ||
@immutable | ||
class FlutterDeckState { | ||
/// Creates a new [FlutterDeckState] with the given parameters. | ||
/// | ||
/// The [locale] and [themeMode] parameters are required. | ||
/// | ||
/// The [markerEnabled], [slideIndex], and [slideStep] parameters are | ||
/// optional. | ||
const FlutterDeckState({ | ||
required this.locale, | ||
required this.themeMode, | ||
this.markerEnabled = false, | ||
this.slideIndex = 0, | ||
this.slideStep = 1, | ||
}); | ||
|
||
/// Creates a new [FlutterDeckState] from a JSON object. | ||
FlutterDeckState.fromJson(Map<String, dynamic> json) | ||
: locale = json['locale'] as String, | ||
markerEnabled = json['markerEnabled'] as bool, | ||
slideIndex = json['slideIndex'] as int, | ||
slideStep = json['slideStep'] as int, | ||
themeMode = json['themeMode'] as String; | ||
|
||
/// Converts this [FlutterDeckState] to a JSON object. | ||
Map<String, dynamic> toJson() => { | ||
'locale': locale, | ||
'markerEnabled': markerEnabled, | ||
'slideIndex': slideIndex, | ||
'slideStep': slideStep, | ||
'themeMode': themeMode, | ||
}; | ||
|
||
/// The locale of the presentation. | ||
final String locale; | ||
|
||
/// Whether the marker is enabled. | ||
final bool markerEnabled; | ||
|
||
/// The index of the current slide. | ||
final int slideIndex; | ||
|
||
/// The step of the current slide. | ||
final int slideStep; | ||
|
||
/// The theme mode of the presentation. | ||
final String themeMode; | ||
|
||
/// Creates a copy of this [FlutterDeckState] with the given parameters | ||
FlutterDeckState copyWith({ | ||
String? locale, | ||
bool? markerEnabled, | ||
int? slideIndex, | ||
int? slideStep, | ||
String? themeMode, | ||
}) { | ||
return FlutterDeckState( | ||
locale: locale ?? this.locale, | ||
markerEnabled: markerEnabled ?? this.markerEnabled, | ||
slideIndex: slideIndex ?? this.slideIndex, | ||
slideStep: slideStep ?? this.slideStep, | ||
themeMode: themeMode ?? this.themeMode, | ||
); | ||
} | ||
|
||
/// Overrides the equality operator to compare two [FlutterDeckState] objects. | ||
@override | ||
bool operator ==(Object other) { | ||
if (identical(this, other)) return true; | ||
|
||
return other is FlutterDeckState && | ||
other.locale == locale && | ||
other.markerEnabled == markerEnabled && | ||
other.slideIndex == slideIndex && | ||
other.slideStep == slideStep && | ||
other.themeMode == themeMode; | ||
} | ||
|
||
/// Overrides the hash code getter to return the hash code of this object. | ||
@override | ||
int get hashCode => | ||
locale.hashCode ^ | ||
markerEnabled.hashCode ^ | ||
slideIndex.hashCode ^ | ||
slideStep.hashCode ^ | ||
themeMode.hashCode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'flutter_deck_state.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: flutter_deck_client | ||
description: A common client interface and models for the flutter_deck package. | ||
version: 0.1.0 | ||
homepage: https://github.com/mkobuolys/flutter_deck | ||
repository: https://github.com/mkobuolys/flutter_deck/tree/main/packages/flutter_deck_client | ||
issue_tracker: https://github.com/mkobuolys/flutter_deck/issues | ||
topics: | ||
- flutterdeck | ||
- presentation | ||
- slides | ||
funding: | ||
- https://github.com/sponsors/mkobuolys | ||
|
||
environment: | ||
sdk: ">=3.0.0 <4.0.0" | ||
|
||
dependencies: | ||
meta: ^1.11.0 | ||
|
||
dev_dependencies: | ||
very_good_analysis: ^5.1.0 |