Masterclass
Masterclass

Reputation: 1

Freely moveable Flutter Widget

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.

Upvotes: 0

Views: 93

Answers (2)

Shakila
Shakila

Reputation: 1059

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(),
            )

Upvotes: 0

Soliev
Soliev

Reputation: 1376

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: () {
              },
            ),
          ),
        ),
      ),
    );
  }
}

Upvotes: 1

Related Questions