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

Qr code #7

Merged
merged 4 commits into from
Nov 2, 2023
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
4 changes: 4 additions & 0 deletions lib/hardware_interface/test_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ class TestHardwareInterface extends BaseHardwareInterface {
database.updateDatabase("test_3", sin(i / 50) + 6);

database.updateDatabase("random_1", random.nextDouble());

database.updateDatabase("qr_code_lat", 50 * sin(i / 50) + 50);
database.updateDatabase("qr_code_lon", -71.0899931);
//database.updateDatabase("qr_code_lat", 42.338807462515526);
}
}
5 changes: 4 additions & 1 deletion lib/widgets/home_pages/desktop_home_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_groundstation/widgets/base_widget.dart';
import 'package:flutter_groundstation/widgets/tabs/qr_code_tab.dart';

import '../../hardware_interface/test_interface.dart';
import '../../hardware_interface/serial_groundstation_interface.dart';
Expand Down Expand Up @@ -36,14 +37,15 @@ class _DesktopHomePageState extends BaseHomePageState<DesktopHomePage> {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
length: 4,
child: Scaffold(
appBar: AppBar(
bottom: const TabBar(
tabs: [
Tab(text: "Test widget"),
Tab(text: "Test tab"),
Tab(text: "Graphs tab"),
Tab(text: "QR Code tab"),
],
),
),
Expand All @@ -55,6 +57,7 @@ class _DesktopHomePageState extends BaseHomePageState<DesktopHomePage> {
),
const TestTab(),
const GraphTab(),
const QrCodeTab(),
],
),
),
Expand Down
136 changes: 136 additions & 0 deletions lib/widgets/qr_code_widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';
import './base_widget.dart';

// https://pub.dev/packages/qr_flutter
// https://medium.com/podiihq/generating-qr-code-in-a-flutter-app-50de15e39830

class QRCodeImageWidget extends StatelessWidget {
const QRCodeImageWidget(this.type, this.lat, this.lon, {super.key});

final String type;
final double lat;
final double lon;

String getData() {
if (type == "Google") {
return "https://www.google.com/maps/search/?api=1&query=$lat%2C$lon";
} else if (type == "Apple") {
return "https://maps.apple.com/?ll=$lat,$lon&q=Dropped%20Pin";
} else if (type == "Geo") {
return "geo:$lat,$lon";
} else {
return "$lat,$lon";
}
}

@override
Widget build(BuildContext context) {
return Column(children: [
Flexible(
child: QrImageView(
data: getData(),
)),
Text(getData())
]);
}
}

class QRCodeWidget extends StatefulWidget {
const QRCodeWidget({super.key});
@override
_QRCodeWidgetState createState() => _QRCodeWidgetState();
}

class _QRCodeWidgetState extends BaseWidgetState<QRCodeWidget> {
String mapType = 'Google';
String boardType = 'FCB';
bool frozen = false;
double curLat = 0.0;
double curLon = 0.0;

String printFrozen(bool yes) {
return yes ? "frozen" : "not frozen";
}

double getLatNotFrozen() {
if (!frozen) {
curLat = getDatabaseValue("qr_code_lat", 0.0);
}
return curLat;
}

double getLonNotFrozen() {
if (!frozen) {
curLon = getDatabaseValue("qr_code_lon", 0.0);
}
return curLon;
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text('Location QR Code Generator'),
),
body: Center(
child: Container(
child: Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Spacer(),
DropdownButton<String>(
value: mapType,
onChanged: (String? newValue) {
setState(() {
mapType = newValue!;
});
},
items: <String>['Google', 'Apple', 'Geo', 'Raw'].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
const Spacer(),
DropdownButton<String>(
value: boardType,
onChanged: (String? newValue) {
setState(() {
boardType = newValue!;
});
},
items: <String>['FCB', 'EggFinder'].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
const Spacer(),
Text(printFrozen(frozen)),
Checkbox(
value: frozen,
onChanged: (bool? value) {
setState(() {
frozen = value!;
});
},
),
const Spacer(),
],
),
Flexible(
child: QRCodeImageWidget(
mapType,
getLatNotFrozen(),
getLonNotFrozen(),
)),
])),
));
}
}
22 changes: 22 additions & 0 deletions lib/widgets/tabs/qr_code_tab.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';

import '../qr_code_widget.dart';

class QrCodeTab extends StatelessWidget {
const QrCodeTab({super.key});

@override
Widget build(BuildContext context) {
// return GridView.count(
// primary: false,
// padding: const EdgeInsets.all(20),
// crossAxisSpacing: 10,
// mainAxisSpacing: 10,
// crossAxisCount: 3,
// children: <Widget>[
//const QRCodeWidget(),
return const QRCodeWidget();
//],
//);
}
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies:
sdk: flutter
auto_size_text: 3.0.0

qr_flutter: ^4.1.0


# The following adds the Cupertino Icons font to your application.
Expand Down