Bharathh-Raj / level_map

A Flutter library to add a level-map feature with powerful customization options.
BSD 2-Clause "Simplified" License
19 stars 14 forks source link

Add on tap feature on levels #2

Open ayushi15092002 opened 2 years ago

ayushi15092002 commented 2 years ago

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

Thanks!

agelospanagiotakis commented 1 year ago

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');
            },
          ),
        ),
      ),
    );
  }
}