Skip to content

Commit

Permalink
v0.1.1 fix issue ios building
Browse files Browse the repository at this point in the history
  • Loading branch information
salim-lachdhaf committed Dec 14, 2020
1 parent 75417d1 commit 47a373c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
10 changes: 6 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ class MyApp extends StatelessWidget {
//2- second step: setUp navigation observer
navigatorObservers: [SavedLastStateData.instance.navigationObserver],
routes: {
HomePage.route: (context) => HomePage(),
DummyPage.route: (context) => DummyPage(),
},
// restore the route or default to the home page
//3- third step: set initial route
initialRoute: SavedLastStateData.instance.lastRoute ?? "/",
home: HomePage(),
initialRoute: SavedLastStateData.instance.lastRoute ?? HomePage.route,
);
}
}

class HomePage extends StatefulWidget {
static const route = 'home';

@override
_HomePageState createState() => _HomePageState();
}
Expand Down Expand Up @@ -96,7 +98,7 @@ class _HomePageState extends State<HomePage> with LastStateRestoration {
),
RaisedButton(
child: Text("Go next page"),
onPressed: () => Navigator.of(context).pushNamed("/intermediate"),
onPressed: () => Navigator.of(context).pushNamed(DummyPage.route),
),
],
),
Expand All @@ -106,7 +108,7 @@ class _HomePageState extends State<HomePage> with LastStateRestoration {
}

class DummyPage extends StatelessWidget {
static const route = "/intermediate";
static const route = 'intermediate';

@override
Widget build(BuildContext context) {
Expand Down
31 changes: 31 additions & 0 deletions ios/Classes/StateStorage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// StateStorage.swift
// flutter_last_state
//
//
import Foundation

public class StateStorage {
public static let instance = StateStorage()

private var state: [String:Any] = [:]

func update(state: [String: Any]) {
self.state = state;
}

func get() -> [String: Any] {
return self.state
}

public func save(coder: NSCoder) {
NSDictionary(dictionary: ["flutter_state" : state]).encode(with: coder)
}

public func restore(coder: NSCoder) {
self.state = NSDictionary(coder: coder)?.value(forKey: "flutter_state") as? [String : Any] ?? [:]
}

private init() {
}
}

0 comments on commit 47a373c

Please sign in to comment.