flutter_drag_selector 0.0.3 copy "flutter_drag_selector: ^0.0.3" to clipboard
flutter_drag_selector: ^0.0.3 copied to clipboard

drag mouse cursor for select bunch widget in zone

flutter_drag_selector #

drag mouse cursor for select bunch widget in zone

Cursor selector Demo

Getting Started #

Add this to your package's pubspec.yaml file:

dependencies:
  flutter_drag_selector: ^latest

Than, use CursorSelectorWidget wrap your scrollview, and SelectableItem wrap your item widget. The callback selectedChangedCallback of CursorSelectorWidget will pass the selected result with status.

Example code #

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final _list = List.generate(50, (i) => i);

  final _controller = StreamController<(Key?, bool)>.broadcast();

  final scrollController = ScrollController();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    _controller.close();
    scrollController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    Widget buildBox(int index) {
      final id = ValueKey<int>(index);
      return StreamBuilder<(Key?, bool)>(
          stream: _controller.stream.where((e) => e.$1 == id),
          builder: (ctx, snapshot) {
            return SelectableItem(
              key: id,
              child: GestureDetector(
                onTap: () {
                  debugPrint('tap -> $index');
                },
                child: Container(
                  width: 200,
                  height: 200,
                  decoration: BoxDecoration(color: index % 2 == 0 ? Colors.yellow : Colors.lightBlueAccent),
                  alignment: Alignment.center,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        '$index',
                        style: const TextStyle(fontSize: 20),
                      ),
                      const SizedBox(
                        width: 20,
                      ),
                      Icon(
                        (snapshot.data?.$2 ?? false) ? Icons.check_box : Icons.check_box_outline_blank,
                        size: 40,
                        color: Colors.red,
                      )
                    ],
                  ),
                ),
              ),
            );
          });
    }

    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: CursorSelectorWidget(
            scrollController: scrollController,
            selectedChangedCallback: (t) {
              _controller.add(t);
            },
            child: SingleChildScrollView(
              controller: scrollController,
              child: Wrap(
                spacing: 10,
                runSpacing: 10,
                children: _list.map<Widget>(buildBox).toList(),
              ),
            )),
      ),
    );
  }


}
2
likes
0
points
25
downloads

Publisher

unverified uploader

Weekly Downloads

drag mouse cursor for select bunch widget in zone

Homepage
Repository (GitHub)
View/report issues

Topics

#windows #desktop #ui #widget

License

unknown (license)

Dependencies

flutter, flutter_web_plugins, plugin_platform_interface, web

More

Packages that depend on flutter_drag_selector