flutter - Use MausRegion at transformed Element - Stack Overflow

I have a stack with some transformed items to display them radial. Now I want to increase the size of a

I have a stack with some transformed items to display them radial. Now I want to increase the size of an element if one hovers over it in Web or is over it with the finger on mobile. I tried using MausRegion and InkWell but both does not work as there must be some coordinate miscalculation. The mouseover just does not trigger in the right moments.

What is the correct approach to use a Mouse over detection for transformed items?

Code:

final List<IconData> flags = [
          Icons.person,
          Icons.access_alarm,
          Icons.photo,
          Icons.phone,
          Icons.telegram,
        ];
return Stack(
  alignment: Alignment.center,
  children: [
    for (int i = 0; i < flags.length; i++)
      Transform(
        transform: Matrix4.identity()
          ..translate(
            distance *
                cos(
                  radians(
                    -90 + 360 * i / flags.length,
                  ),
                ),
            distance *
                sin(
                  radians(
                    -90 + 360 * i / flags.length,
                  ),
                ),
          ),
        child: MouseRegion(
          cursor: SystemMouseCursors.click,
          onEnter: (_) => ref
              .read(
                selectedSherlockRadialItemControllerProvider(i).notifier,
              )
              .setTrue(),
          onExit: (_) => ref
              .read(
                selectedSherlockRadialItemControllerProvider(i).notifier,
              )
              .setFalse(),
          child: CircleAvatar(
            backgroundColor: Colors.green,
            minRadius: circleSize,
            child: Icon(
              flags[i],
              color: Colors.white,
              size: circleSize,
            ),
          ),
        ),
      )
          .animate(
            target:
                ref.watch(selectedSherlockRadialItemControllerProvider(i))
                    ? 1
                    : 0,
          )
          .scaleXY(
            alignment: Alignment.center,
            begin: 1,
            end: 1.2,
          ),
  ],
);

Here is a minimal example showing that onPressed from a Button is not even working:

import 'package:flutter/material.dart';
import 'dart:math';
import 'package:vector_math/vector_math.dart' show radians;

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    final List<IconData> flags = [
      Icons.person,
      Icons.access_alarm,
      Icons.photo,
      Icons.phone,
      Icons.telegram,
    ];

    const double distance = 125;
    const double circleSize = 45;

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: Stack(
            alignment: Alignment.center,
            children: [
              for (int i = 0; i < flags.length; i++)
                Transform(
                  transform: Matrix4.identity()
                    ..translate(
                      distance *
                          cos(
                            radians(
                              -90 + 360 * i / flags.length,
                            ),
                          ),
                      distance *
                          sin(
                            radians(
                              -90 + 360 * i / flags.length,
                            ),
                          ),
                    ),
                  child: FloatingActionButton(
                    onPressed: () {
                      print('goockk');
                    },
                    child: Icon(
                      flags[i],
                      color: Colors.white,
                      size: circleSize,
                    ),
                  ),
                ),
            ],
          ),
        ),
      ),
    );
  }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745299256a4621334.html

相关推荐

  • flutter - Use MausRegion at transformed Element - Stack Overflow

    I have a stack with some transformed items to display them radial. Now I want to increase the size of a

    8小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信