flutter_toggle_animated 1.0.0 copy "flutter_toggle_animated: ^1.0.0" to clipboard
flutter_toggle_animated: ^1.0.0 copied to clipboard

A new Flutter package for simplifying the creation of Animated Controller for creating various animations.

example/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_toggle_animated/flutter_toggle_animated.dart';

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

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

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  late ToggleController _animatedController;

  @override
  void initState() {
    _animatedController = ToggleController(
        vsync: this, animationDuration: const Duration(milliseconds: 500))
      ..addListener(() {
        setState(() {});
      });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text("Animate Toggle"),
      ),
      body: Stack(
        children: [
          Center(
            child: ElevatedButton(
              onPressed: () {
                _animatedController.toggle();
              },
              child: Text("Toggle"),
            ),
          ),
          FractionalTranslation(
            translation:
                Offset(1.0 - _animatedController.currentPercentOpen, 0.0),
            child: Align(
              alignment: Alignment.centerRight,
              child: Container(
                width: 150,
                height: double.infinity,
                color: Colors.black54,
                child: buildColumn(),
              ),
            ),
          )
        ],
      ),
    );
  }

  Column buildColumn() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        BuildListButtons(
          icon: Icons.settings,
          txt: "Settings",
          fun: () => _animatedController.close(),
        ),
        BuildListButtons(
          icon: Icons.supervised_user_circle,
          txt: "Friends",
          fun: () => _animatedController.close(),
        ),
        BuildListButtons(
          icon: Icons.folder,
          txt: "Directory",
          fun: () => _animatedController.close(),
        ),
        BuildListButtons(
          icon: Icons.security,
          txt: "Security",
          fun: () => _animatedController.close(),
        ),
        BuildListButtons(
          icon: Icons.notifications,
          txt: "Notifications",
          fun: () => _animatedController.close(),
        ),
      ],
    );
  }

  @override
  void dispose() {
    _animatedController.dispose();
    super.dispose();
  }
}

class BuildListButtons extends StatelessWidget {
  const BuildListButtons({
    Key? key,
    this.icon,
    this.txt,
    this.fun,
  }) : super(key: key);

  final IconData? icon;
  final String? txt;
  final VoidCallback? fun;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: fun,
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Icon(
            icon,
            color: Colors.white,
            size: 40,
          ),
          SizedBox(
            height: 10,
          ),
          Text(
            txt!,
            style: TextStyle(
                color: Colors.white, fontWeight: FontWeight.bold, fontSize: 16),
          )
        ],
      ),
    );
  }
}
2
likes
130
pub points
0%
popularity

Publisher

verified publishercodingloops.com

A new Flutter package for simplifying the creation of Animated Controller for creating various animations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_toggle_animated