Skip to content

Commit

Permalink
chore: Added the padding of a cell in the draw badge screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhalakupadhyay committed Nov 23, 2024
1 parent 9f77806 commit fc520cf
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 153 deletions.
53 changes: 0 additions & 53 deletions lib/bademagic_module/utils/byte_array_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,56 +53,3 @@ List<List<bool>> hexStringToBool(String hexString) {

return boolArray;
}

List<List<int>> byteArrayToBinaryArray(List<int> byteArray) {
List<List<int>> binaryArray = List.generate(11, (_) => []);

int rowIndex = 0;
for (int byte in byteArray) {
List<int> binaryRepresentation = [];
for (int i = 7; i >= 0; i--) {
binaryRepresentation.add((byte >> i) & 1);
}

binaryArray[rowIndex].addAll(binaryRepresentation);

rowIndex = (rowIndex + 1) % 11;
}

logger.d(
"binaryArray: $binaryArray"); // Use print instead of logger for standalone example
return binaryArray;
}

String hexToBin(String hex) {
// Convert hex to binary string
String binaryString = BigInt.parse(hex, radix: 16).toRadixString(2);

// Pad the binary string with leading zeros if necessary to ensure it's a multiple of 8 bits
int paddingLength = (8 - (binaryString.length % 8)) % 8;
binaryString = binaryString.padLeft(binaryString.length + paddingLength, '0');
logger.d("binaryString: $binaryString");
return binaryString;
}

List<List<int>> binaryStringTo2DList(String binaryString) {
int maxHeight = 11;
List<List<int>> binary2DList = List.generate(maxHeight, (_) => []);

for (int x = 0; x < binaryString.length; x++) {
int a = 0;
for (int y = a; y < 11; y++) {
for (int z = 0; z < 8; z++) {
binary2DList[y].add(int.parse(binaryString[x++]));
if (x >= binaryString.length) {
break;
}
}
if (x >= binaryString.length) {
break;
}
}
}
logger.d("binary2DList: $binary2DList");
return binary2DList;
}
1 change: 0 additions & 1 deletion lib/view/about_us_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class _AboutUsScreenState extends State<AboutUsScreen> {
@override
void initState() {
_setOrientation();
// TODO: implement initState
super.initState();
}

Expand Down
203 changes: 104 additions & 99 deletions lib/view/draw_badge_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ class _DrawBadgeState extends State<DrawBadge> {
return CommonScaffold(
index: 1,
title: 'BadgeMagic',
body: Column(
children: [
Expanded(
child: Container(
margin: EdgeInsets.symmetric(vertical: 20.h, horizontal: 20.w),
padding: EdgeInsets.all(10.dg),
height: 390.h,
body: Padding(
padding: EdgeInsets.only(top: 20.h, right: 20.w, left: 20.w),
child: Column(
children: [
Container(
padding: EdgeInsets.only(
top: 37.h, left: 32.h, right: 30.h, bottom: 30.h),
height: 400.h,
width: 500.w,
decoration: BoxDecoration(
color: Colors.black,
Expand All @@ -76,105 +77,109 @@ class _DrawBadgeState extends State<DrawBadge> {
.toList(),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () {
setState(() {
drawToggle.toggleIsDrawing(true);
});
},
child: Column(
children: [
Icon(
Icons.edit,
color:
drawToggle.getIsDrawing() ? Colors.red : Colors.black,
),
Text(
'Draw',
style: TextStyle(
color: drawToggle.isDrawing ? Colors.red : Colors.black,
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextButton(
onPressed: () {
setState(() {
drawToggle.toggleIsDrawing(true);
});
},
child: Column(
children: [
Icon(
Icons.edit,
color: drawToggle.getIsDrawing()
? Colors.red
: Colors.black,
),
)
],
Text(
'Draw',
style: TextStyle(
color:
drawToggle.isDrawing ? Colors.red : Colors.black,
),
)
],
),
),
),
TextButton(
onPressed: () {
setState(() {
drawToggle.toggleIsDrawing(false);
});
},
child: Column(
children: [
Icon(
Icons.delete,
color: drawToggle.isDrawing ? Colors.black : Colors.red,
),
Text(
'Erase',
style: TextStyle(
TextButton(
onPressed: () {
setState(() {
drawToggle.toggleIsDrawing(false);
});
},
child: Column(
children: [
Icon(
Icons.delete,
color: drawToggle.isDrawing ? Colors.black : Colors.red,
),
)
],
Text(
'Erase',
style: TextStyle(
color:
drawToggle.isDrawing ? Colors.black : Colors.red,
),
)
],
),
),
),
TextButton(
onPressed: () {
setState(() {
drawToggle.resetDrawViewGrid();
});
},
child: const Column(
children: [
Icon(
Icons.refresh,
color: Colors.black,
),
Text(
'Reset',
style: TextStyle(color: Colors.black),
)
],
TextButton(
onPressed: () {
setState(() {
drawToggle.resetDrawViewGrid();
});
},
child: const Column(
children: [
Icon(
Icons.refresh,
color: Colors.black,
),
Text(
'Reset',
style: TextStyle(color: Colors.black),
)
],
),
),
),
TextButton(
onPressed: () {
List<List<int>> badgeGrid = drawToggle
.getDrawViewGrid()
.map((e) => e.map((e) => e ? 1 : 0).toList())
.toList();
List<String> hexString =
Converters.convertBitmapToLEDHex(badgeGrid, false);
widget.isSavedCard!
? fileHelper.updateBadgeText(
widget.filename!,
hexString,
)
: widget.isSavedClipart!
? fileHelper.updateClipart(
widget.filename!, badgeGrid)
: fileHelper.saveImage(drawToggle.getDrawViewGrid());
fileHelper.generateClipartCache();
ToastUtils().showToast("Clipart Saved Successfully");
},
child: const Column(
children: [
Icon(
Icons.save,
color: Colors.black,
),
Text('Save', style: TextStyle(color: Colors.black))
],
TextButton(
onPressed: () {
List<List<int>> badgeGrid = drawToggle
.getDrawViewGrid()
.map((e) => e.map((e) => e ? 1 : 0).toList())
.toList();
List<String> hexString =
Converters.convertBitmapToLEDHex(badgeGrid, false);
widget.isSavedCard!
? fileHelper.updateBadgeText(
widget.filename!,
hexString,
)
: widget.isSavedClipart!
? fileHelper.updateClipart(
widget.filename!, badgeGrid)
: fileHelper
.saveImage(drawToggle.getDrawViewGrid());
fileHelper.generateClipartCache();
ToastUtils().showToast("Clipart Saved Successfully");
},
child: const Column(
children: [
Icon(
Icons.save,
color: Colors.black,
),
Text('Save', style: TextStyle(color: Colors.black))
],
),
),
),
],
)
],
],
)
],
),
),
key: const Key(drawBadgeScreen),
);
Expand Down

0 comments on commit fc520cf

Please sign in to comment.