level_map icon indicating copy to clipboard operation
level_map copied to clipboard

Add on tap feature on levels

Open ayushi15092002 opened this issue 3 years ago • 1 comments

Hi! Would it be possible to navigate to other screen on tapping of completed level and current level?

Thanks!

ayushi15092002 avatar Mar 26 '22 12:03 ayushi15092002

that would be really nice feature! i would love to add it to my game!

that might work

import 'package:flutter/material.dart';

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

class MyPainter extends CustomPainter {
  final Function(Offset) onRectClicked;

  MyPainter({required this.onRectClicked});

  @override
  void paint(Canvas canvas, Size size) {
    // Draw a rectangle
    final rect = Rect.fromPoints(Offset(50, 50), Offset(200, 200));
    final paint = Paint()..color = Colors.blue;
    canvas.drawRect(rect, paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return false;
  }

  @override
  bool hitTest(Offset position) {
    final rect = Rect.fromPoints(Offset(50, 50), Offset(200, 200));

    if (rect.contains(position)) {
      onRectClicked(position);
      return true; // Consider the hit as handled
    }

    return false; // Consider the hit as not handled
  }
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Rect Click Example'),
        ),
        body: CustomPaint(
          painter: MyPainter(
            onRectClicked: (position) {
              print('You clicked inside the rect at $position');
            },
          ),
        ),
      ),
    );
  }
}

agelospanagiotakis avatar Oct 27 '23 12:10 agelospanagiotakis