Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updated the draw View logic feature. #1041

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/providers/badgeview_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'package:badgemagic/badge_animation/ani_right.dart';
import 'package:badgemagic/badge_animation/ani_snowflake.dart';
import 'package:badgemagic/badge_animation/ani_up.dart';
import 'package:badgemagic/badge_animation/animation_abstract.dart';
import 'package:badgemagic/badge_effect/badgeeffectabstract.dart';
import 'package:badgemagic/badge_effect/badge_effect_impl.dart';
import 'package:badgemagic/badge_effect/badgeeffectabstract.dart';
import 'package:badgemagic/constants.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -41,8 +41,8 @@ class DrawBadgeProvider extends ChangeNotifier {
List<List<bool>> getDrawViewGrid() => drawViewGrid;

//setter for the drawViewGrid
void setDrawViewGrid(List<List<bool>> newGrid) {
drawViewGrid = newGrid;
void setDrawViewGrid(int row, int col) {
drawViewGrid[row][col] = isDrawing;
notifyListeners();
}

Expand All @@ -57,7 +57,7 @@ class DrawBadgeProvider extends ChangeNotifier {

//function to reset the state of the cell
void resetGrid() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Potential bug in resetGrid method

The resetGrid method is now resetting drawViewGrid instead of homeViewGrid. Is this change intentional? If not, it could lead to unexpected behavior.

homeViewGrid = List.generate(11, (i) => List.generate(44, (j) => false));
drawViewGrid = List.generate(11, (i) => List.generate(44, (j) => false));
notifyListeners();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/view/draw_badge_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class _DrawBadgeState extends State<DrawBadge> {
),
TextButton(
onPressed: () {
fileHelper.saveImage(drawToggle.getGrid());
fileHelper.saveImage(drawToggle.getDrawViewGrid());
},
child: const Column(
children: [
Expand Down
4 changes: 3 additions & 1 deletion lib/view/homescreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
@override
void initState() {
inlineImageProvider.getController().addListener(_controllerListner);
drawBadgeProvider.resetGrid();
WidgetsBinding.instance.addPostFrameCallback((_) {
drawBadgeProvider.resetGrid();
});
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
Expand Down
28 changes: 14 additions & 14 deletions lib/virtualbadge/view/badge_home_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:badgemagic/providers/badgeview_provider.dart';
import 'package:badgemagic/virtualbadge/widgets/badge_widget.dart';
import 'package:badgemagic/virtualbadge/view/badgehome_paint.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
Expand All @@ -16,18 +16,18 @@ class _BMBadgeHomeState extends State<BMBadgeHome> {
Widget build(BuildContext context) {
final grid = Provider.of<DrawBadgeProvider>(context).getGrid();
return Container(
margin: EdgeInsets.only(top: 8.h, left: 15.w, right: 15.w),
padding: EdgeInsets.all(8.dg),
height: 100.h,
width: 500.w,
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(color: Colors.black),
borderRadius: BorderRadius.circular(10),
),
child: BadgeWidget(
grid: grid,
),
);
margin: EdgeInsets.only(top: 8.h, left: 15.w, right: 15.w),
padding: EdgeInsets.all(8.dg),
height: 100.h,
width: 500.w,
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(color: Colors.black),
borderRadius: BorderRadius.circular(10),
),
child: CustomPaint(
size: const Size(400, 480),
painter: BadgeHomePaint(grid: grid),
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'dart:math' as math;

import 'package:flutter/material.dart';

class BadgePainter extends CustomPainter {
class BadgeHomePaint extends CustomPainter {
final List<List<bool>> grid;

BadgePainter({required this.grid});
BadgeHomePaint({required this.grid});

@override
void paint(Canvas canvas, Size size) {
Expand Down
14 changes: 7 additions & 7 deletions lib/virtualbadge/view/draw_badge.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:badgemagic/providers/badgeview_provider.dart';
import 'package:badgemagic/virtualbadge/widgets/badge_widget.dart';
import 'package:badgemagic/virtualbadge/view/draw_badge_paint.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:provider/provider.dart';
Expand All @@ -26,18 +26,18 @@ class _BMBadgeState extends State<BMBadge> {
int row = (localPosition.dy / cellHeight).clamp(0, rows - 1).toInt();

setState(() {
cellStateToggle.updateGrid(row, col);
cellStateToggle.setDrawViewGrid(row, col);
});
}

@override
Widget build(BuildContext context) {
final grid = Provider.of<DrawBadgeProvider>(context).getDrawViewGrid();
return GestureDetector(
onPanUpdate: _handlePanUpdate,
child: BadgeWidget(
grid: grid,
),
);
onPanUpdate: _handlePanUpdate,
child: CustomPaint(
size: const Size(400, 480),
painter: DrawBadgePaint(grid: grid),
));
}
}
45 changes: 45 additions & 0 deletions lib/virtualbadge/view/draw_badge_paint.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:flutter/material.dart';
import 'dart:math' as math;

class DrawBadgePaint extends CustomPainter {
final List<List<bool>> grid;

const DrawBadgePaint({required this.grid});

@override
void paint(Canvas canvas, Size size) {
double cellWidth = size.width / grid[0].length;
double cellHeight = size.height / grid.length;

for (int row = 0; row < grid.length; row++) {
for (int col = 0; col < grid[row].length; col++) {
final Paint paint = Paint()
..color = grid[row][col] ? Colors.red : Colors.grey.shade900
..style = PaintingStyle.fill;

final Path path = Path()
..moveTo(col * cellWidth, row * cellHeight)
..lineTo(col * cellWidth + cellWidth * 0.4, row * cellHeight)
..lineTo(col * cellWidth + cellWidth * 0.655,
row * cellHeight + cellHeight)
..lineTo(
col * cellWidth + cellWidth * 0.25, row * cellHeight + cellHeight)
..close();

const double radians = math.pi / 4;
canvas.save();
canvas.translate((col + 0.5) * cellWidth, (row + 0.5) * cellHeight);
canvas.rotate(radians);
canvas.translate(-(col + 0.5) * cellWidth, -(row + 0.5) * cellHeight);

canvas.drawPath(path, paint);
canvas.restore();
}
}
}

@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
23 changes: 0 additions & 23 deletions lib/virtualbadge/widgets/badge_widget.dart

This file was deleted.

Loading