-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
593 additions
and
261 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
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,32 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:octopus/src/controller/state_codec.dart'; | ||
import 'package:octopus/src/state/state.dart'; | ||
|
||
/// Converts between [RouteInformation] and [OctopusState]. | ||
/// {@nodoc} | ||
@internal | ||
class OctopusInformationParser implements RouteInformationParser<OctopusState> { | ||
/// {@nodoc} | ||
OctopusInformationParser() : _codec = const OctopusStateCodec(); | ||
|
||
final OctopusStateCodec _codec; | ||
|
||
@override | ||
Future<OctopusState> parseRouteInformationWithDependencies( | ||
RouteInformation routeInformation, | ||
BuildContext context, | ||
) => | ||
parseRouteInformation(routeInformation); | ||
|
||
@override | ||
Future<OctopusState> parseRouteInformation(RouteInformation route) => | ||
SynchronousFuture<OctopusState>(_codec.encode(route)); | ||
|
||
@override | ||
RouteInformation? restoreRouteInformation(OctopusState state) => | ||
_codec.decode(state); | ||
} |
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
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
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,40 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
import 'package:octopus/src/state/state.dart'; | ||
|
||
/// Converts [RouteInformation] to [OctopusState] and vice versa. | ||
class OctopusStateCodec extends Codec<RouteInformation, OctopusState> { | ||
/// Converts [RouteInformation] to [OctopusState] and vice versa. | ||
const OctopusStateCodec(); | ||
|
||
@override | ||
Converter<RouteInformation, OctopusState> get encoder => | ||
const OctopusStateEncoder(); | ||
|
||
@override | ||
Converter<OctopusState, RouteInformation> get decoder => | ||
const OctopusStateDecoder(); | ||
} | ||
|
||
/// Converts [RouteInformation] to [OctopusState]. | ||
class OctopusStateEncoder extends Converter<RouteInformation, OctopusState> { | ||
/// Converts [RouteInformation] to [OctopusState]. | ||
const OctopusStateEncoder(); | ||
|
||
@override | ||
OctopusState convert(RouteInformation input) => | ||
OctopusState.fromUri(input.uri); | ||
} | ||
|
||
/// Converts [OctopusState] to [RouteInformation]. | ||
class OctopusStateDecoder extends Converter<OctopusState, RouteInformation> { | ||
/// Converts [OctopusState] to [RouteInformation]. | ||
const OctopusStateDecoder(); | ||
|
||
@override | ||
RouteInformation convert(covariant OctopusState input) => RouteInformation( | ||
uri: input.uri, | ||
/* state: input, */ | ||
); | ||
} |
Oops, something went wrong.