Line data Source code
1 : import 'dart:convert'; 2 : 3 : import 'package:flutter/foundation.dart'; 4 : import 'package:flutter/widgets.dart'; 5 : 6 : import 'beam_state.dart'; 7 : 8 : /// Converts [RouteInformation] to [BeamState] and vice-versa. 9 : class BeamerRouteInformationParser extends RouteInformationParser<BeamState> { 10 7 : @override 11 : SynchronousFuture<BeamState> parseRouteInformation( 12 : RouteInformation routeInformation) { 13 14 : final uri = Uri.parse(routeInformation.location ?? '/'); 14 7 : return SynchronousFuture( 15 7 : BeamState.fromUri( 16 : uri, 17 7 : data: routeInformation.state == null 18 6 : ? {} 19 1 : : Map<String, String>.from( 20 2 : json.decode(routeInformation.state as String), 21 : ), 22 : ), 23 : ); 24 : } 25 : 26 7 : @override 27 : RouteInformation restoreRouteInformation(BeamState beamState) { 28 7 : return RouteInformation( 29 14 : location: beamState.uri.toString(), 30 14 : state: json.encode(beamState.data), 31 : ); 32 : } 33 : }