IgnorePointer example in flutter

This Article is posted by seven.srikanth at 1/9/2023 4:37:00 AM



In Flutter, the IgnorePointer widget is a non-visual widget that ignores pointers, or touch events, that are dispatched to its children. This can be useful in cases where you want to disable user interaction with a widget or a group of widgets, but still want the widgets to be visible and participate in layout.
Here is an example of how to use the IgnorePointer widget in a Flutter application:

import 'package:flutter/material.dart';
void main() {
  runApp(const MyApp());
}
class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @ override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: IgnorePointer(
            ignoring: true, // Set to true to ignore pointers
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                ElevatedButton(
                  child: const Text('This button is not interactive'),
                  onPressed: () {
                    // Button press will not be registered
                  },
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
In this example, the IgnorePointer widget is used to ignore pointers that are dispatched to its child widgets (a Text widget and a RaisedButton widget). This means that the user will not be able to interact with these widgets, but they will still be visible and participate in layout.
You can toggle the ignoring of pointers by setting the ignoring property of the IgnorePointer widget to true or false. When set to true, the widget will ignore pointers, and when set to false, it will allow pointers to be dispatched to its children.
Thanks,
Srikanth

Tags:








0 Comments
Login to comment.
Recent Comments

Be the first to Comment. You can ask a Query or Share your toughts or Just say thanks.


© 2018 - Fluttercentral | Email to me - seven.srikanth@gmail.com