Giter Club home page Giter Club logo

fluttercandies / flutter_tilt Goto Github PK

View Code? Open in Web Editor NEW
131.0 4.0 5.0 39.61 MB

๐Ÿ‘€ Easily apply tilt parallax hover effects for Flutter, which supports tilt, light, shadow effects, and gyroscope sensors | ไธบ Flutter ่ฝปๆพๅˆ›ๅปบๅ€พๆ–œ่ง†ๅทฎๆ‚ฌๅœๆ•ˆๆžœ๏ผŒๆ”ฏๆŒๅ€พๆ–œใ€ๅ…‰็…งใ€้˜ดๅฝฑๆ•ˆๆžœๅ’Œ้™€่žบไปชไผ ๆ„Ÿๅ™จ

Home Page: https://pub.dev/packages/flutter_tilt

License: MIT License

Dart 100.00%
flutter hover parallax tilt animation flutter-package sensors widget

flutter_tilt's Introduction

GitHub stars Pub.dev likes

๐Ÿ““ Language: English | ไธญๆ–‡
๐ŸŽ Check out the Live Demo.
๐Ÿ’ก See the Migration Guide to learn how to migrate between breaking changes.



Flutter Tilt

stable package dev package pub points CodeFactor codecov top language

Easily Apply Tilt Parallax Hover Effects for Flutter!


Example Preview GIF - Parallax image
Example Preview GIF
Example Preview GIF - Parallax card
Example Preview GIF - Layout

Check out the Live Demo.


Table of contents ๐Ÿช„


Features โœจ

  • ๐Ÿ“ฆ Tilt effect
  • ๐Ÿ”ฆ Light effect
  • ๐Ÿ’ก Shadow effect
  • ๐Ÿ‘€ Parallax effect
  • ๐Ÿ“ฑ Gyroscope sensor support (Sensors compatibility)
  • ๐Ÿงฑ Multiple layouts
  • ๐Ÿ‘‡ Supports hover, touch and sensors events
  • ๐Ÿ–ผ๏ธ Smooth animation
  • โš™๏ธ Many custom parameters

Install ๐ŸŽฏ

Versions compatibility ๐Ÿฆ

Flutter 3.0.0+ 3.10.0+ 3.19.0+
flutter_tilt 3.0.0+ โŒ โŒ โœ…
flutter_tilt 2.0.0+ โŒ โœ… โœ…
flutter_tilt 1.0.0+ โœ… โŒ โŒ

Add package ๐Ÿ“ฆ

Run this command with Flutter,

$ flutter pub add flutter_tilt

or add flutter_tilt to pubspec.yaml dependencies manually.

dependencies:
  flutter_tilt: ^latest_version

Sensors compatibility ๐Ÿ“ฑ

Sensors are triggered only on these platforms.

Android iOS Web (HTTPS) macOS Linux Windows
โœ… โœ… Browser compatibility โŒ โŒ โŒ

Note

Currently Web uses the Sensor API - Gyroscope, but it is not compatible with some of the major browsers, such as Safari, Firefox.

Gesture priority ๐Ÿ“ฑ

When multiple gestures are enabled, they are triggered based on priority:

Touch > Hover > Controller > Sensors

Simple usage ๐Ÿ“–

Example: flutter_tilt/example

Tilt ๐Ÿ“ฆ

Tilt widget will have default tilt, shadow, and light effects.

/// Import flutter_tilt
import 'package:flutter_tilt/flutter_tilt.dart';

Tilt(
  child: Container(
    width: 150.0,
    height: 300.0,
    color: Colors.grey,
  ),
),

Parallax ๐Ÿ‘€

TiltParallax widget can only be used in the childLayout of Tilt widget.

/// Import flutter_tilt
import 'package:flutter_tilt/flutter_tilt.dart';

Tilt(
  childLayout: const ChildLayout(
    outer: [
      /// Parallax here
      Positioned(
        child: TiltParallax(
          child: Text('Parallax'),
        ),
      ),
      /// Parallax here
      Positioned(
        top: 20.0,
        left: 20.0,
        child: TiltParallax(
          size: Offset(-10.0, -10.0),
          child: Text('Tilt'),
        ),
      ),
    ],
  ),
  child: Container(
    width: 150.0,
    height: 300.0,
    color: Colors.brown,
  ),
),

Usage ๐Ÿ“–

Tilt widget parameters ๐Ÿค–

Parameter Type Default Description
child required Widget - Create a widget that its child widget can be tilted.
childLayout ChildLayout ChildLayout() Other child layouts.
e.g. parallax outer, inner, behind.
tiltStreamController StreamController<TiltStreamModel>? null StreamController<TiltStreamModel>.broadcast() to control the tilt.
disable bool false Disable all effects.
fps int 60 Gesture triggered frames.
border BoxBorder? null BoxDecoration border.
borderRadius BorderRadiusGeometry? null BoxDecoration borderRadius.
clipBehavior Clip Clip.antiAlias Flutter clipBehavior.
tiltConfig TiltConfig TiltConfig() Tilt effect config.
lightConfig LightConfig LightConfig() Light effect config.
shadowConfig ShadowConfig ShadowConfig() Shadow effect config.
onGestureMove void Function(TiltDataModel, GesturesType)? null Gesture move callback.
onGestureLeave void Function(TiltDataModel, GesturesType)? null Gesture leave callback.

TiltParallax widget parameters ๐Ÿค–

Parameter Type Default Description
child required Widget - Create a widget with parallax.
size Offset Offset(10.0, 10.0) Parallax size.
filterQuality FilterQuality null Flutter FilterQuality.

ChildLayout ๐Ÿ“„

Parameter Type Default Description
outer List<Widget> <Widget>[] As with Stack, you can use the Stack layout to create widgets that are outer of the child.
e.g. parallax effects.
inner List<Widget> <Widget>[] As with Stack, you can use the Stack layout to create widgets that are inner of the child.
e.g. parallax effects.
behind List<Widget> <Widget>[] As with Stack, you can use the Stack layout to create widgets that are behind of the child.
e.g. parallax effects.

StreamController<TiltStreamModel> ๐Ÿ“„

final StreamController<TiltStreamModel> tiltStreamController =
      StreamController<TiltStreamModel>.broadcast();

/// The current gesture is being used
tiltStreamController.add(
  TiltStreamModel(
    position: Offset(xx, xx),
  ),
);

/// Stop using the current gesture
tiltStreamController.add(
  TiltStreamModel(
    position: Offset(xx, xx),
    gestureUse: false,
  ),
);
Parameter Type Default Description
position required Offset - The current trigger position,
It will have the tilt effect of the corresponding position.
e.g.
There is a widget size, width: 10, height: 10,
(0, 0): Maximum tilt top left.
(10, 10): Maximum tilt bottom right.
gesturesType GesturesType GesturesType.controller Trigger gesture type.
It is triggered according to the gesture priority.
If you need to customize the control with animation or other means.
Recommended use of GesturesType.controller.
If other types are used for triggering,
Then it will be affected by the configuration and effects associated with that type.
e.g.
When custom triggering GesturesType.sensors.
If TiltConfig.enableSensorRevert is configured to be false,
it will also not revert to the initial state.
gestureUse bool true Whether the gesture is being used.
It is used to determine if the gesture is being used and will be processed according to the gesture priority.
e.g.
If GesturesType.touch is never assigned false when triggered, gestures with a lower priority than GesturesType.touch will never be triggered.

TiltConfig ๐Ÿ“„

Parameter Type Default Description
disable bool false Only disable the tilt effect.
initial Offset? null Initial tilt progress, range (x, y): (1, 1) to (-1, -1),
you can exceed the range, but the maximum tilt angle during gesture movement is always tilted according to [TiltConfig.angle].
e.g. (0.0, 0.0) center
(1.0, 1.0) Maximum tilt top left [TiltConfig.angle].
angle double 10.0 Maximum tilt angle.
e.g. 180 will flip.
direction List<TiltDirection>? null Tilt Direction, multiple directions, customized direction values.
enableReverse bool false Tilt reverse, can be tilted up or down.
filterQuality FilterQuality null Flutter FilterQuality.
enableGestureSensors bool true Gyroscope sensor triggered tilt.
Only the following gestures:
GesturesType.sensors
sensorFactor double 10.0 Sensor trigger factor (sensitivity).
Only the following gestures:
GesturesType.sensors
enableSensorRevert bool true Enable sensor tilt revert, will revert to the initial state.
Only the following gestures:
GesturesType.sensors
sensorRevertFactor double 0.05 Sensor revert factor (damping), range of values: 0-1.
Only the following gestures:
GesturesType.sensors
sensorMoveDuration Duration Duration(milliseconds: 50) Animation duration during sensor move.
Only the following gestures:
GesturesType.sensors
enableGestureHover bool true Hover gesture triggered tilt.
Only the following gestures:
GesturesType.hover
enableGestureTouch bool true Touch gesture triggered tilt.
Only the following gestures:
GesturesType.touch
enableRevert bool true Enable tilt revert, will revert to the initial state.
Only the following gestures:
GesturesType.touch
GesturesType.hover
GesturesType.controller
enableOutsideAreaMove bool true Tilt can continue to be triggered outside the area.
Only the following gestures:
GesturesType.touch
GesturesType.controller
moveDuration Duration Duration(milliseconds: 100) Animation duration during gesture move.
Only the following gestures:
GesturesType.touch
GesturesType.hover
leaveDuration Duration Duration(milliseconds: 300) Animation duration after gesture leave.
Only the following gestures:
GesturesType.touch
GesturesType.hover
moveCurve Curve Curves.linear Animation curve during gesture move.
Only the following gestures:
GesturesType.touch
GesturesType.hover
leaveCurve Curve Curves.linear Animation curve after gesture leave.
Only the following gestures:
GesturesType.touch
GesturesType.hover
controllerMoveDuration Duration Duration(milliseconds: 100) Animation duration during controller gesture move.
Only the following gestures:
GesturesType.controller
controllerLeaveDuration Duration Duration(milliseconds: 300) Animation duration after controller gesture leave.
Only the following gestures:
GesturesType.controller

LightConfig ๐Ÿ“„

Parameter Type Default Description
disable bool false Only disable the light effect.
color Color Color(0xFFFFFFFF) Light color.
minIntensity double 0.0 Color minimum opacity, also initial opacity.
maxIntensity double 0.5 Color maximum opacity for tilt progresses.
spreadFactor double 4.0 Light spread factor, relative to current widget size.
direction LightDirection LightDirection.around Light direction.
Affects:
[ShadowConfig.direction] (not affected after configuration).
enableReverse bool false Reverse light direction.
Affects:
[ShadowConfig.direction] (not affected after configuration).
[ShadowConfig.enableReverse] (not affected after configuration).

ShadowConfig ๐Ÿ“„

Parameter Type Default Description
disable bool false Only disable the shadow effect.
color Color Color(0xFF9E9E9E) Shadow color.
minIntensity double 0.0 Color minimum opacity, also initial opacity.
maxIntensity double 0.5 Color maximum opacity as tilt progresses.
offsetInitial Offset Offset(0.0, 0.0) Initial value of shadow offset.
e.g. (0.0, 0.0) center.
(40.0, 40.0) Offset 40 to the top left.
offsetFactor double 0.1 Shadow offset factor, relative to current widget size.
spreadInitial double 0.0 Initial value of shadow spread radius.
spreadFactor double 0.0 Shadow spread radius factor, relative to current widget size.
minBlurRadius double 10.0 Minimum blur radius, also initial blur radius.
maxBlurRadius double 20.0 Maximum blur radius for tilt progresses.
direction ShadowDirection? null Shadow direction.
enableReverse bool? null Reverse shadow direction.

Contributors โœจ

AmosHuKe
AmosHuKe

License ๐Ÿ“„

MIT License
Open sourced under the MIT license.

ยฉ AmosHuKe

flutter_tilt's People

Contributors

amoshuke avatar dependabot[bot] avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flutter_tilt's Issues

[Bug report] Black bars when using in mobile browser.

Version

3.0.1

Platforms

Web - Only in mobile browser

Device Model

Samsung Galaxy S22 Ultra

Flutter info

[โœ“] Flutter (Channel stable, 3.19.5, on macOS 14.4.1 23E224 darwin-arm64, locale en-US)
    โ€ข Flutter version 3.19.5 on channel stable at /Users/firdous.ismail/development/flutter
    โ€ข Upstream repository https://github.com/flutter/flutter.git
    โ€ข Framework revision 300451adae (3 weeks ago), 2024-03-27 21:54:07 -0500
    โ€ข Engine revision e76c956498
    โ€ข Dart version 3.3.3
    โ€ข DevTools version 2.31.1

[โœ“] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    โ€ข Android SDK at /Users/firdous.ismail/Library/Android/sdk
    โ€ข Platform android-34, build-tools 34.0.0
    โ€ข Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    โ€ข Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    โ€ข All Android licenses accepted.

[โœ“] Xcode - develop for iOS and macOS (Xcode 15.3)
    โ€ข Xcode at /Applications/Xcode.app/Contents/Developer
    โ€ข Build 15E204a
    โ€ข CocoaPods version 1.15.2

[โœ—] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[โœ“] Android Studio (version 2023.2)
    โ€ข Android Studio at /Applications/Android Studio.app/Contents
    โ€ข Flutter plugin can be installed from:
      ๐Ÿ”จ https://plugins.jetbrains.com/plugin/9212-flutter
    โ€ข Dart plugin can be installed from:
      ๐Ÿ”จ https://plugins.jetbrains.com/plugin/6351-dart
    โ€ข Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[โœ“] VS Code (version 1.88.1)
    โ€ข VS Code at /Applications/Visual Studio Code.app/Contents
    โ€ข Flutter extension version 3.86.0

[โœ“] Connected device (2 available)
    โ€ข sdk gphone64 arm64 (mobile) โ€ข emulator-5554 โ€ข android-arm64 โ€ข Android 13 (API 33) (emulator)
    โ€ข macOS (desktop)             โ€ข macos         โ€ข darwin-arm64  โ€ข macOS 14.4.1 23E224 darwin-arm64

[โœ“] Network resources
    โ€ข All expected network resources are available.

! Doctor found issues in 1 category.

How to reproduce?

The app is essentially unusable when the Tilt widget is active and running on any mobile browser, although it functions properly when tested on a desktop browser. For the first two Tilt widgets, all I can see are black bars, and below them, another card with a Tilt widget appears washed out. Moreover, none of the other widgets are visible. I tested on Edge mobile browser, and Samsung browser. I deployed using Firebase hosting, you can also test it yourself with below URL. I'll attach screenshots below.

Hosted using Firebase hosting here
https://firdous.web.app

Mobile browser screenshot
image

Desktop browser screenshot (In inspect mode)
image

Minimal example code (optional)

Tilt(
  tiltConfig: const TiltConfig(angle: 12.0, enableGestureSensors: false),
  shadowConfig: ShadowConfig(disable: !shadow),
  borderRadius: BorderRadius.circular(radius),
  child: child,
);

I must say, it's a fantastic and incredibly helpful package. Thanks in advance.

Tilt & Hold Position? Or Tilt to Pan?

Hi, wondering if it's possible that when you tilt and keep it tilted that the position stays until you tilt it back to origin? This could be fun to be able to peek behind things or pan around a widget.

It has been implemented on the Motion Package
mrcendre/motion#8

Tapping Moves Entire Content

When I set enableRevert & enableSensorRevert to false,

How to reproduce
run the example app

Steps to reproduce the behavior:

  1. set enableRevert & enableSensorRevert to false
  2. tap on counter widget or FAB
  3. see the content tilt and the FAB gets moved away from your finger

Expected behavior
I want the FAB to be able to move around and be tappable without moving or moving the content. so it can move independently and still interact.
i do want to be able to move the counter widget by panning around. maybe have a "disable" control option or something?

maybe this is just a limitation of the example. perhaps some other use case examples would be beneficial. there are a ton of use cases such as revealing hidden content, panning content around, and dropping a ball into a hole (target)

iPhone 12

[Feature request] Need to set tilt programmatically.

Platforms

Android, iOS

Description

Hi, Thank you for your awesome plugin. That's amazing animation.
However, I need to know Can I set tilt by not from user interaction? but from code to animate widget.

Thank in advanced.

Why

In case need to animate ifself for interval duration to tilt widget over and over again.
Also, Can we add depth to make it look like it has more dimension?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.