skip to Main Content

I need a special Widget.

Hey, I need the name pros.

Is there a widget that can be moved freely. Like how you can just move on with maps?

So basically scrollable in all directions.

2

Answers


  1. You can check InteractiveViewer
    Her is a basic demo:

    import 'package:flutter/material.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      static const String _title = 'Flutter Code Sample';
    
      @override
      Widget build(BuildContext context) {
        return const MaterialApp(
          title: _title,
          home: HomePage(),
        );
      }
    }
    
    class HomePage extends StatefulWidget {
      const HomePage({super.key});
    
      @override
      State<HomePage> createState() => _HomePageState();
    }
    
    class _HomePageState extends State<HomePage> {
      late Offset _offset;
    
      @override
      void initState() {
        _offset = const Offset(0, 0);
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(title: Text(_offset.toString())),
          body: SizedBox.expand(
            child: InteractiveViewer(
              onInteractionUpdate: (details) => setState(() {
                _offset = details.focalPoint;
              }),
              boundaryMargin: const EdgeInsets.all(1000.0),
              minScale: 0.1,
              maxScale: 3,
              child: Center(
                child: TextButton(
                  child: const Text('Drag me'),
                  onPressed: () {
                  },
                ),
              ),
            ),
          ),
        );
      }
    }
    
    
    Login or Signup to reply.
  2. You can use draggable widget for that simply wrap your widget like this

    Draggable(
                  data: 'Flutter',
                  child: FlutterLogo(
                    size: 100.0,
                  ),
                  feedback: FlutterLogo(
                    size: 100.0,
                  ),
                  childWhenDragging: Container(),
                )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search