Yosua Martiansia
Yosua Martiansia

Reputation: 135

How to achieve this result in flutter?

enter image description here

How to have the notch appear whenever a tab is selected in Flutter? And how to animate the change by having the notch slide whenever another tab is selected?

Thank you for the help in advance

Upvotes: 0

Views: 196

Answers (1)

Aldy Yuan
Aldy Yuan

Reputation: 2045

This is the workaround that I can do : import 'package:flutter/material.dart';

void main() => runApp(MyApp());

/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: MyStatefulWidget(),
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  MyStatefulWidget({Key key}) : super(key: key);

  @override
  _MyStatefulWidgetState createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  int _selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Row(
        children: <Widget>[
          NavigationRail(
            selectedIndex: _selectedIndex,
            onDestinationSelected: (int index) {
              setState(() {
                _selectedIndex = index;
              });
            },
            labelType: NavigationRailLabelType.selected,
            destinations: [
              NavigationRailDestination(
                icon: Text("Food"),
                label: Container(
                    width: 8,
                    height: 8,
                    decoration: BoxDecoration(
                      color: Colors.red,
                      shape: BoxShape.circle,
                    )),
              ),
              NavigationRailDestination(
                icon: Text("Bakery"),
                label: Container(
                    width: 8,
                    height: 8,
                    decoration: BoxDecoration(
                      color: Colors.red,
                      shape: BoxShape.circle,
                    )),
              ),
              NavigationRailDestination(
                icon: Text("Drinks"),
                label: Container(
                    width: 8,
                    height: 8,
                    decoration: BoxDecoration(
                      color: Colors.red,
                      shape: BoxShape.circle,
                    )),
              ),
            ],
          ),
          VerticalDivider(thickness: 1, width: 1),
          // This is the main content.
          Expanded(
            child: Center(
              child: Text(
                'selectedIndex: $_selectedIndex',
                style: Theme.of(context).textTheme.headline4,
              ),
            ),
          )
        ],
      ),
    );
  }
}

You could use NavigationRail for Side Bar. But I'm not sure how to make the notch, anyway I hope this can help you a bit

Upvotes: 1

Related Questions