diff --git a/cyberwow/lib/main.dart b/cyberwow/lib/main.dart index 4e3f29f..c621f6b 100644 --- a/cyberwow/lib/main.dart +++ b/cyberwow/lib/main.dart @@ -73,9 +73,6 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv AppState _state; AppLifecycleState _notification = AppLifecycleState.resumed; - final syncedPageController = PageController( - initialPage: 1, - ); bool _exiting = false; @@ -213,7 +210,7 @@ class _CyberWOW_PageState extends State with WidgetsBindingObserv (s) => widget.buildBlank(context, s), (s) => widget.buildLoading(context, s), (s) => widget.buildSyncing(context, s), - (s) => widget.buildSynced(context, s, syncedPageController), + (s) => widget.buildSynced(context, s), (s) => widget.buildReSyncing(context, s), (s) => widget.buildExiting(context, s), ), diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index 1bf5078..2760d72 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -215,7 +215,10 @@ class SyncingState extends HookedState { // processInput.add('exit'); final _height = await rpc.height(); - SyncedState _next = SyncedState(setState, getNotification, isExiting, stdout, processInput, processOutput); + SyncedState _next = SyncedState + ( + setState, getNotification, isExiting, stdout, processInput, processOutput, 1, + ); _next.height = _height; return moveState(_next); } @@ -232,17 +235,26 @@ class SyncedState extends HookedState { String syncInfo = 'syncInfo'; List getConnections = []; List getTransactionPool = []; + int pageIndex; - FocusNode focusNode = FocusNode(); - TextEditingController textController = TextEditingController(); + final FocusNode focusNode = FocusNode(); + final TextEditingController textController = TextEditingController(); + PageController pageController; - SyncedState(f1, f2, f3, this.stdout, this.processInput, this.processOutput) : super (f1, f2, f3); + SyncedState(f1, f2, f3, this.stdout, this.processInput, this.processOutput, this.pageIndex) + : super (f1, f2, f3) { + pageController = PageController( initialPage: pageIndex ); + } void appendInput(String line) { stdout.addLast('> ' + line + '\n'); processInput.add(line); } + void onPageChanged(int value) { + this.pageIndex = value; + } + Future next() async { log.fine("Synced next"); @@ -300,7 +312,7 @@ class SyncedState extends HookedState { ReSyncingState _next = ReSyncingState ( - setState, getNotification, isExiting, stdout, processInput, processOutput + setState, getNotification, isExiting, stdout, processInput, processOutput, pageIndex ); return moveState(_next); } @@ -312,8 +324,10 @@ class ReSyncingState extends HookedState { StreamSink processInput; Stream processOutput; bool synced = false; + final int pageIndex; - ReSyncingState(f1, f2, f3, this.stdout, this.processInput, this.processOutput) : super (f1, f2, f3); + ReSyncingState(f1, f2, f3, this.stdout, this.processInput, this.processOutput, this.pageIndex) + : super (f1, f2, f3); void append(String msg) { stdout.addLast(msg); @@ -364,7 +378,7 @@ class ReSyncingState extends HookedState { log.fine('resync: await exit'); SyncedState _next = SyncedState ( - setState, getNotification, isExiting, stdout, processInput, processOutput + setState, getNotification, isExiting, stdout, processInput, processOutput, pageIndex ); _next.height = await rpc.height(); return moveState(_next); diff --git a/cyberwow/lib/widget/synced.dart b/cyberwow/lib/widget/synced.dart index 24a9e04..3e1a285 100644 --- a/cyberwow/lib/widget/synced.dart +++ b/cyberwow/lib/widget/synced.dart @@ -225,24 +225,25 @@ Widget terminalView(BuildContext context, String title, SyncedState state) { Widget terminal(BuildContext context, SyncedState state) => terminalView(context, 'terminal', state); -Widget pageView (BuildContext context, SyncedState state, PageController controller) { +Widget pageView (BuildContext context, SyncedState state) { return PageView ( - controller: controller, + controller: state.pageController, + onPageChanged: state.onPageChanged, children: [ terminal(context, state), summary(context, state), getTransactionPool(context, state), - getInfo(context, state), getConnections(context, state), + getInfo(context, state), // syncInfo(state), ], ); } -Widget buildSynced(BuildContext context, SyncedState state, PageController controller) { +Widget buildSynced(BuildContext context, SyncedState state) { return Scaffold ( - body: pageView(context, state, controller) + body: pageView(context, state) ); }