Switcher constructor

const Switcher({
  1. Key? key,
  2. int index = 0,
  3. required AxisDirection direction,
  4. required List<Widget> children,
  5. ValueChanged<int>? onIndexChanged,
  6. Duration duration = const Duration(milliseconds: 300),
  7. Curve curve = Curves.easeInOut,
})

Creates a Switcher.

The direction and children parameters are required. The index determines which child is initially visible.

Parameters:

  • index (int, default: 0): initial active child index
  • direction (AxisDirection, required): swipe transition direction
  • children (List
  • onIndexChanged (ValueChanged
  • duration (Duration, default: 300ms): transition animation duration
  • curve (Curve, default: Curves.easeInOut): transition animation curve

Example:

Switcher(
  index: 0,
  direction: AxisDirection.left,
  duration: Duration(milliseconds: 250),
  curve: Curves.easeOut,
  onIndexChanged: (index) => print('Switched to $index'),
  children: [
    Text('First view'),
    Text('Second view'),
    Text('Third view'),
  ],
);

Implementation

const Switcher({
  super.key,
  this.index = 0,
  required this.direction,
  required this.children,
  this.onIndexChanged,
  this.duration = const Duration(milliseconds: 300),
  this.curve = Curves.easeInOut,
});