如何在颤振中实现这一结果?

时间:2020-08-18 06:06:13

标签: flutter flutter-layout flutter-animation

enter image description here

每当在Flutter中选择一个标签时,如何显示该缺口? 以及如何通过每当选择另一个标签具有槽口滑动动画改变?

谢谢您的帮助

1 个答案:

答案 0 :(得分:0)

这是我可以做的解决方法: 导入'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,
              ),
            ),
          )
        ],
      ),
    );
  }
}

您可以将NavigationRail用于侧边栏。但是我不确定如何进行切槽,无论如何我希望这可以对您有所帮助