MarcinusX / buy_ticket_design

The UI Challenge in Flutter
https://marcinszalek.pl/flutter/tickets-challenge-parallax/
851 stars 216 forks source link

How to use tabs Nearby and Notice to open separate page #4

Closed azhankhan05 closed 5 years ago

azhankhan05 commented 5 years ago

There's a stateless tabs page with two constructors of text and isSelected.

class Tabs extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.end,
      children: <Widget>[
        SizedBox(width: 24),
        MyTab(text: 'Nearby', isSelected: false),
        MyTab(text: 'Recent', isSelected: true),
        MyTab(text: 'Notice', isSelected: false),
      ],
    );
  }
}

class MyTab extends StatelessWidget {
  final String text;
  final bool isSelected;

  const MyTab({Key key, @required this.isSelected, @required this.text})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            text,
            style: TextStyle(
              fontSize: isSelected ? 16 : 14,
              color: isSelected ? Colors.black : Colors.grey,
              fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
            ),
          ),
          Container(
            height: 6,
            width: 20,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(4),
              color: isSelected ? Color(0xFFFF5A1D) : Colors.white,
            ),
          )
        ],
      ),
    );
  }
}
And this page is called in home_Page.dart-
class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Stack(
        children: <Widget>[
          SafeArea(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                SizedBox(height: 8),
                Header(),
                SizedBox(height: 40),
                Tabs(),
                SizedBox(height: 8),
                SlidingCardsView(),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

As you can see that the SlidingCardsView() is called below the tabs, but I want to open the SlidingCardsView() on clicking the recent tab and further PageOne() to Nearby and PageTwo() to notice tabs. Can anyone help me with this?.

MarcinusX commented 5 years ago

Hey, I can see two approaches to that. One is to expose a public function from SlidingCardView, create the GlobalKey in the parent widget and pass it to the SlidingCardView. This way you can do key.currentState.changePage(index). Inside this function, you can call pageController to animate to the given page.