Giter VIP home page Giter VIP logo

Comments (4)

AmosHuKe avatar AmosHuKe commented on June 11, 2024 1

@jtkeyva

Yes and when tapping on the "container" was causing it to tilt was well. Is there a feature to set tap to false?

Currently, Quick Tap cannot gracefully handle gesture competition.
Tilt can only be triggered by moving and long-pressing.

So in your instance, how would the FAB be off screen upon load? Then you can tilt to reveal it?

Upgrading to version 2.0.4
You can try this sample:

Code sample
import 'package:flutter/material.dart';

import 'package:flutter_tilt/flutter_tilt.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Tilt Demo',
      theme: ThemeData(
        primarySwatch: Colors.brown,
      ),
      home: const TiltDemo(),
    );
  }
}

class TiltDemo extends StatefulWidget {
  const TiltDemo({super.key});

  @override
  State<TiltDemo> createState() => _TiltDemoState();
}

class _TiltDemoState extends State<TiltDemo> {
  int _counter = 0;

  bool enableGestureTouch = true;
  bool enableGestureHover = true;
  bool enableGestureSensors = true;

  Offset position = const Offset(-25, -25);

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color(0xFFFFFFFF),
      body: Center(
        child: Tilt(
          borderRadius: BorderRadius.circular(24),
          tiltConfig: TiltConfig(
            angle: 20,
            enableRevert: false,
            enableSensorRevert: false,
            enableGestureSensors: enableGestureSensors,
            enableGestureHover: enableGestureHover,
            enableGestureTouch: enableGestureTouch,
          ),
          lightConfig: const LightConfig(
            minIntensity: 0.1,
          ),
          shadowConfig: const ShadowConfig(
            minIntensity: 0.05,
            maxIntensity: 0.4,
            offsetFactor: 0.08,
            minBlurRadius: 10,
            maxBlurRadius: 15,
          ),
          childLayout: ChildLayout(
            inner: [
              Positioned(
                top: 200,
                child: TiltParallax(
                  size: const Offset(-20, -20),
                  child: Text(
                    '$_counter',
                    style: const TextStyle(fontSize: 20),
                  ),
                ),
              ),
              Positioned(
                bottom: position.dy,
                right: position.dx,
                child: TiltParallax(
                  size: const Offset(35, 35),
                  child: Listener(
                    onPointerDown: (e) {
                      setState(() {
                        enableGestureTouch = false;
                        enableGestureHover = false;
                        enableGestureSensors = false;
                      });
                    },
                    onPointerMove: (event) {
                      setState(() {
                        position -= event.delta;
                      });
                    },
                    onPointerUp: (event) {
                      setState(() {
                        enableGestureTouch = true;
                        enableGestureHover = true;
                        enableGestureSensors = true;
                      });
                    },
                    child: SizedBox(
                      width: 50,
                      height: 50,
                      child: FloatingActionButton(
                        onPressed: _incrementCounter,
                        tooltip: 'Increment',
                        child: const Icon(Icons.add),
                      ),
                    ),
                  ),
                ),
              ),
            ],
          ),
          // onGestureMove:
          //     (TiltDataModel tiltDataModel, GesturesType gesturesType) {
          //   print('--- onGestureMove ---');
          //   print(tiltDataModel.areaProgress);
          //   print(gesturesType.name);
          // },
          // onGestureLeave:
          //     (TiltDataModel tiltDataModel, GesturesType gesturesType) {
          //   print('--- onGestureLeave ---');
          //   print(tiltDataModel.areaProgress);
          //   print(gesturesType.name);
          // },
          child: const MyHomePage(title: 'Flutter Tilt Demo'),
        ),
      ),
    );
  }
}

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 250,
      height: 450,
      child: Scaffold(
        backgroundColor: const Color(0x206D6E6F),
        appBar: AppBar(
          title: Text(
            widget.title,
            style: const TextStyle(fontSize: 18),
          ),
        ),
        body: const Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'You have pushed the button this many times',
                style: TextStyle(fontSize: 10),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

from flutter_tilt.

AmosHuKe avatar AmosHuKe commented on June 11, 2024

Hi~ @jtkeyva, Thanks for the suggestion.

Is this the effect you need?

  1. Tapping when enableRevert or enableSensorRevert is false will not cause tilt.
  2. FAB can be moved around and the rest of the content doesn't tilt with it (hypothetical example, mainly showing the competition of gestures).
Screenrecorder-2023-09-20-20-35-22-774.mp4

from flutter_tilt.

jtkeyva avatar jtkeyva commented on June 11, 2024

Hi thanks. Yes and when tapping on the "container" was causing it to tilt was well. Is there a feature to set tap to false?

That is a cool example. It also shows a feature that i wanted to try... have content off screen that becomes visible when you tilt or swipe to reveal. So in your instance, how would the FAB be off screen upon load? Then you can tilt to reveal it?

Very cool!

from flutter_tilt.

jtkeyva avatar jtkeyva commented on June 11, 2024

@AmosHuKe thank you! that gives me a good head start :) and yes, tapping bug is now fixed :)

from flutter_tilt.

Related Issues (10)

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.