Как вернуть основной PageView из вложенных элементов PageView? - PullRequest
0 голосов
/ 30 октября 2018

У меня есть демонстрационное приложение Flutter, использующее PageView и BottomNavigationBar. Моя вложенная страница выглядит так:

  • PageTwo
    • PageTwoAccount - PageTwoAccountDetails

Из PageTwoAccountDetails мне нужно вернуться на страницу PageTwo. В моем демонстрационном приложении ниже, когда я это делаю, он показывает значок и имя PageTwo, но показывает PageOne как вид. Кажется, что когда я возвращаюсь из вложенного PageView мой PageView и BottomNavigationBar больше не синхронизируются.

Я не уверен, если вопрос правильный, но Как мне вернуть основной PageView из вложенных элементов PageView?

// TODO: HomePage
class MyUserHomePage extends StatefulWidget {
  final int titleIndex;
  final String cUserNo;

  MyUserHomePage(
      {Key key,
      this.titleIndex,
      this.cUserNo})
      : super(key: key);

  @override
  _MyUserHomePageState createState() => new _MyUserHomePageState();
}

class _MyUserHomePageState extends State<MyUserHomePage> {

  PageController _pageController;
  int _page;

  // TODO: 1 - INIT STATE
  @override
  void initState() {
    super.initState();
    this._page = widget.titleIndex;
    _pageController = new PageController();
  }

  // TODO: 2 - NAVIGATION TAPPED ANIMATION
  void navigationTapped(int page) {
    _pageController.animateToPage(page,
        duration: const Duration(milliseconds: 800), curve: Curves.ease);
  }

  // TODO: 3 - ON PAGE CHANGED
  void onPageChanged(int page) {
    if (this.mounted) {
      setState(() {
        this._page = page;
      });
    }
  }

// TODO: 4 - DISPOSE
  @override
  void dispose() {
    super.dispose();
    _pageController.dispose();
    this._page = null;
  }

new Scaffold(
  body: new PageView(
    children: [
      new PageOneSummary(
          index: this._page,
          cUserNo: "${widget.cUserNo}"),
      new PageTwo(
          index: this._page,
          cUserNo: "${widget.cUserNo}"),
    ],
    onPageChanged: onPageChanged,
    controller: _pageController,
  ),
  bottomNavigationBar: new Theme(
    data: Theme.of(context).copyWith(
        // Sets the background color of the 'BottomNavigationBar'
        canvasColor: cDarkGreen,
        // Sets the active color of the 'BottomNavigationBar'
        primaryColor: cGreen,
        // Sets the inactive color of the `BottomNavigationBar`
        textTheme: Theme.of(context)
            .textTheme
            .copyWith(caption: new TextStyle(color: Colors.white))),
    child: new BottomNavigationBar(
      items: [
        new BottomNavigationBarItem(
          icon: new Icon(Icons.account_balance_wallet),
          title: new Text(
            “PageOne”,
            style: new TextStyle(
                color: Colors.white, fontWeight: FontWeight.bold),
          ),
        ),
        new BottomNavigationBarItem(
          icon: new Icon(Icons.credit_card),
          title: new Text(
            “PageTwo”,
            style: new TextStyle(
                color: Colors.white, fontWeight: FontWeight.bold),
          ),
        ),

      ],
      onTap: navigationTapped,
      currentIndex: this._page,
    ),
  ),
)
...