Smueez / floating_animated_widget

a flutter package for floating widget
Other
17 stars 10 forks source link

Features

Demo

Without auto align Initially "autoAlign" is false.

    autoAlign = false

Auto align activated Add this to your code.

    autoAlign = true

Deletion of the widget Add this to your code.

    deleteWidget: Icon(Icons.cancel),

Getting started

Install

add this in your pubspec.yaml floating_draggable_widget: ^latest_version

Class

This is the constructor of the class.

     FloatingDraggableWidget({
        required this.mainScreenWidget,
        required this.floatingWidget,
        required this.floatingWidgetWidth,
        required this.floatingWidgetHeight,
        this.dy,
        this.dx,
        this.screenHeight,
        this.screenWidth,
        this.speed,
        this.isDraggble = true,
        this.autoAlign = false,
        this.deleteWidgetAlignment = Alignment.bottomCenter,
        this.deleteWidgetAnimationDuration = 200,
        this.hasDeleteWidgetAnimationDuration = 300,
        this.deleteWidgetAnimationCurve = Curves.easeIn,
        this.deleteWidgetHeight = 50,
        this.deleteWidgetWidth = 50,
        this.isCollidingDeleteWidgetHeight = 70,
        this.isCollidingDeleteWidgetWidth = 70,
        this.deleteWidgetDecoration,
        this.deleteWidgetPadding = const EdgeInsets.only(bottom: 8),
        this.onDragging,
        this.widgetWhenDragging,
    });

Where:

import 'package:flutter/material.dart';
import 'package:floating_animated_widget/floating_draggable_widget.dart';
void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(

        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {

      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {

    return FloatingDraggableWidget(
      child: Scaffold(
        appBar: AppBar(

          title: Text(widget.title),
        ),
        body: Center(

          child: Column(

            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const Text(
                'You have pushed the button this many times:',
              ),
              Text(
                '$_counter',
                style: Theme.of(context).textTheme.headline4,
              ),
            ],
          ),
        ),
      ),
      floatingWidget: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
      floatingWidgetHeight: 40,
      floatingWidgetWidth: 40,
      dx: 200,
      dy: 300
    );
  }
}

Known Limitations