Skip to content

A Flutter Widget wrapper that enables vertical and horizontal dragging to flip the front and back widget.

License

Notifications You must be signed in to change notification settings

harlanx/flippable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flippable

A Flutter Widget wrapper that enables vertical and horizontal dragging to flip the front and back widget.

I do not plan on releasing it in pub.dev. Feel free to fork it.

Features

  • Horizontal Dragging
  • Vertical Dragging
  • Both Direction Dragging (Only one single axis is active when dragging)
  • Revert (Always animate back to front)
  • Controller (to listen to values and flip programatically)
  • onChanged Callback
  • True orientation (Correction of orientation of back widget will be disabled)

Preview

Usage

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

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}

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

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

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

class _HomeScreenState extends State<HomeScreen> {
  final FlippableController _controller = FlippableController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: Colors.white,
        alignment: Alignment.center,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              child: Text('Flip It!'),
              onPressed: () {
                if (_controller.isFront) {
                  _controller.flipTo(180);
                } else {
                  _controller.flipTo(0.0);
                }
              },
            ),
            SizedBox(height: 10),
            Text('Is Widget Front: ${_controller.isFront}'),
            SizedBox(
              height: 400,
              width: 400,
              child: Flippable(
                controller: _controller,
                dragAxis: DragAxis.vertical,
                revert: false,
                duration: Duration(milliseconds: 600),
                curve: Curves.easeInOut,
                onChanged: (value) {
                  setState(() {});
                  print('isFront: $value');
                },
                frontWidget: Image.asset(
                  'assets/images/credit_card_front.png',
                  fit: BoxFit.contain,
                ),
                backWidget: Image.asset(
                  'assets/images/credit_card_back.png',
                  fit: BoxFit.contain,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

About

A Flutter Widget wrapper that enables vertical and horizontal dragging to flip the front and back widget.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages