Skip to content

Commit

Permalink
Merge pull request #10 from KlubJagiellonski/feature/3
Browse files Browse the repository at this point in the history
Making barcodes clickable and displaying them on the home page
  • Loading branch information
karolgeneral authored Jul 4, 2024
2 parents abe14e8 + 3247135 commit 4c5c5f8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
29 changes: 29 additions & 0 deletions lib/barcode_detail_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'package:flutter/material.dart';
import 'barcode_item.dart';
import 'package:barcode_widget/barcode_widget.dart';

class BarcodeDetailPage extends StatelessWidget {
final BarcodeItem barcode;

const BarcodeDetailPage({super.key, required this.barcode});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Opis Kodu Kreskowego'),
automaticallyImplyLeading: false, // removes button "Back"
),
body: Center(
child: BarcodeWidget(
barcode: barcode.type,
data: barcode.data,
width: 300,
height: 150,
drawText: true,
style: const TextStyle(fontSize: 16, letterSpacing: 1.5),
),
),
);
}
}
41 changes: 28 additions & 13 deletions lib/barcodes_page.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import 'package:flutter/material.dart';
import 'package:flutter/material.dart';
import 'barcode_item.dart';
import 'package:barcode_widget/barcode_widget.dart';
import 'barcode_detail_page.dart';

class BarcodesPage extends StatelessWidget {
const BarcodesPage({
super.key,
required this.barcodes,
});


final List<BarcodeItem> barcodes;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Lista Kodów Kreskowych'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView.builder(
Expand All @@ -26,14 +29,10 @@ class BarcodesPage extends StatelessWidget {
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Row(
children: [
Expanded(
child: BarcodeItemWidget(barcode: leftBarcode),
),
const SizedBox(width: 10),
_buildBarcodeItem(context, leftBarcode),
const SizedBox(width: 10),
if (rightBarcode != null)
Expanded(
child: BarcodeItemWidget(barcode: rightBarcode),
),
_buildBarcodeItem(context, rightBarcode),
],
),
);
Expand All @@ -42,6 +41,22 @@ class BarcodesPage extends StatelessWidget {
),
);
}

Widget _buildBarcodeItem(BuildContext context, BarcodeItem barcode) {
return Expanded(
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => BarcodeDetailPage(barcode: barcode),
),
);
},
child: BarcodeItemWidget(barcode: barcode),
),
);
}
}

class BarcodeItemWidget extends StatelessWidget {
Expand All @@ -64,19 +79,19 @@ class BarcodeItemWidget extends StatelessWidget {
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 6),
const SizedBox(height: 6),
BarcodeWidget(
barcode: barcode.type,
data: barcode.data,
width: 200,
width: 200,
height: 100,
drawText: true,
style: const TextStyle(
fontSize: 16,
fontSize: 16,
letterSpacing: 1.5,
),
),
],
);
}
}
}

0 comments on commit 4c5c5f8

Please sign in to comment.