0

I am trying to factor out some code(inspired from this)

part "game.dart":

part 'taps.dart';

class MyGame extends FlameGame with HasTappables {}

Trying to factor out to this file "taps.dart":

part of 'game.dart';

mixin Taps on MyGame {

  @override
  void onTapDown(int pointerId, TapDownInfo info) {
    super.onTapDown(pointerId, info);
}

Problem is that "onTapDown" is not called?

Update:

This will not work:

class MainClass with OneMixin {
  void test(){
    helloOne();
  }
}

mixin OneMixin on MainClass {
  void helloOne() {
    test();
  }
}
Chris G.
  • 23,930
  • 48
  • 177
  • 302
  • 1
    Your first example doesn't use the `Taps` mixin and uses some other `HasTappables` mixin instead. Assuming that your `Taps` mixin was meant to be named `HasTappables`, that example and the example from your update don't make sense because they're circular. `class MainClass with OneMixin` means that `MainClass` derives from an automatically generated class that copies `OneMixin`'s implementation (which in turn depends on `MainClass`). I highly recommend reading [lrn's explanation for mixins](https://stackoverflow.com/a/45903671/). – jamesdlin Mar 23 '22 at 18:43
  • 1
    Also, none of this involves or is related to `part`/`part of`. That's a completely independent concept from mixins. – jamesdlin Mar 23 '22 at 18:48

1 Answers1

1

Something like this would work:

abstract class FlameGame {
  int? a;
}

class MyGame extends FlameGame with Taps {
  int? b;
}

mixin Taps on FlameGame {
  void method() {
    print(a); // Possible
    print(b); // Not possible
    print((this as MyGame).b); // possible but unsave
  }
}
puaaaal
  • 196
  • 8