stacker 0.1.0 copy "stacker: ^0.1.0" to clipboard
stacker: ^0.1.0 copied to clipboard

A collection of 3 widgets that stack their children, displaying a single child at a time, transitioning between children when a different child is displayed. Stacker can be used modularly as a compone [...]

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:modular_menu/modular_menu.dart';
import 'package:stacker/stacker.dart';
import 'my_stack_swapper.dart';
import 'my_stack_switcher.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Stacker Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Stacker Demo'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  /// A [Stacker] with a [MyStackSwapper] as the root widget,
  /// set up to handle a single-page navigation system.
  final Stacker _myStacker = Stacker(
    MyStackSwapper(),
    maintainStates: true,
    backButton: true,
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        actions: [
          // Back Navigation Button
          NavigationButton(
            Icons.arrow_back,
            onTap: _myStacker.back,
            setState: setState,
            enabled: _myStacker.canNavigateBack,
          ),
          // Forward Navigation Button
          NavigationButton(
            Icons.arrow_forward,
            onTap: _myStacker.forward,
            setState: setState,
            enabled: _myStacker.canNavigateForward,
          ),
        ],
      ),
      drawer: Drawer(
        child: ModularMenu(
          [
            // Build and navigate to a new [MyStackSwapper] when pressed.
            MenuButton('StackSwapper', onTap: () {
              _myStacker.build(MyStackSwapper());
              setState(() {});
            }),
            // Build and navigate to a new [MyStackSwitcher] when pressed.
            MenuButton('StackSwitcher', onTap: () {
              _myStacker.build(MyStackSwitcher());
              setState(() {});
            }),
          ],
          // Close the drawer when any button is pressed.
          onTapAny: () => Navigator.pop(context),
        ),
      ),
      body: _myStacker,
    );
  }
}

typedef StateSetter = void Function(void Function());

class NavigationButton extends StatelessWidget {
  const NavigationButton(
    this.icon, {
    @required this.onTap,
    @required this.setState,
    @required this.enabled,
  })  : assert(icon != null),
        assert(onTap != null),
        assert(setState != null),
        assert(enabled != null);

  final IconData icon;

  final GestureTapCallback onTap;

  final StateSetter setState;

  final bool enabled;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: enabled
          ? () {
              onTap();
              setState(() {});
            }
          : null,
      child: Container(
        width: 48.0,
        child: Center(
          child: Icon(icon, color: enabled ? Colors.white : Colors.white30),
        ),
      ),
    );
  }
}
1
likes
30
pub points
0%
popularity

Publisher

verified publisherjamesalex.dev

A collection of 3 widgets that stack their children, displaying a single child at a time, transitioning between children when a different child is displayed. Stacker can be used modularly as a component, to drive single-page apps, or to control multi-step flows within a widget or page.

Repository (GitHub)
View/report issues

License

BSD-2-Clause (LICENSE)

Dependencies

fade_and_translate, flutter, provider

More

Packages that depend on stacker