skip to Main Content

In Flutter I have a SingleChildScrollView with a Column with many Text children.
Besides the Text children there is one HandSignature widget (from this package).

When using your finger to draw onto the signature, it would trigger the scroll of the SingleChildScrollView. Which is why I need to exclude the scrolling behaviour from this widget.

3

Answers


  1. Wrap your HandSignature with NotificationListener like this

    child: NotificationListener<ScrollNotification>(
      onNotification: (notification) {
       //do not bubble up the  notification
       return true;
      },
     child: HandSignature()
    )
    
    Login or Signup to reply.
  2. Change position of HandSignature to be on AlertDialog

    Login or Signup to reply.
  3. Here’s a way to lock and unlock your scroll. Add a bool variable that would be responsible for wether the screen should be scrollable at the moment. change its value when user interacts with signature widget and call setState. If scroll is locked, set scrollPhysics to NeverScrollableScrollPhysics(), otherwise it should be null.
    For simple example I did a button that locks the scroll. You can check this snippet in Dartpad.

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          home: Scaffold(body: ScrollWithLock()),
        );
      }
    }
    
    class ScrollWithLock extends StatefulWidget {
      const ScrollWithLock({Key? key}) : super(key: key);
    
      @override
      State<ScrollWithLock> createState() => _ScrollWithLockState();
    }
    
    class _ScrollWithLockState extends State<ScrollWithLock> {
      var isScrollLocked = false;
      @override
      Widget build(BuildContext context) {
        return SingleChildScrollView(
          physics: isScrollLocked ? NeverScrollableScrollPhysics() : null,
          child: Column(children: [
            for (var i = 0; i < 10; i++)
              const Padding(
                padding: EdgeInsets.all(20),
                child: Text('This is scrollable'),
              ),
            ElevatedButton(
              child: SizedBox(
                height: 100,
                width: 200,
                child: Text(isScrollLocked ? 'Locked' : 'Unlocked'),
              ),
              onPressed: () {
                setState(() {
                  isScrollLocked = !isScrollLocked;
                });
              },
            ),
            for (var i = 0; i < 10; i++)
              const Padding(
                padding: EdgeInsets.all(20),
                child: Text('This is scrollable'),
              ),
          ]),
        );
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search