master
hoba_razor 4 years ago
parent bca3b7e5fb
commit 1d8ad5489a
  1. 3
      android/app/src/main/AndroidManifest.xml
  2. 41
      lib/main.dart

@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.contact_tracing">
<application
android:label="contact_tracing"
android:label="Contact Tracing"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
@ -39,4 +39,5 @@
</intent>
</queries>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.VIBRATE"/>
</manifest>

@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:flutter_sms/flutter_sms.dart';
@ -16,7 +17,8 @@ class AnalyzeView extends StatefulWidget {
class AnalyzeViewState extends State<AnalyzeView>
with SingleTickerProviderStateMixin {
String? barcode;
double number = 1;
double peopleCount = 1;
final String prefix = 'smsto:1922:';
MobileScannerController controller = MobileScannerController(
torchEnabled: false,
@ -26,10 +28,14 @@ class AnalyzeViewState extends State<AnalyzeView>
void _sendSMS(String message, List<String> recipents) async {
String _result = await sendSMS(message: message, recipients: recipents)
.catchError((onError) {
if (kDebugMode) {
print('sms err: $onError');
}
});
if (kDebugMode) {
print('sms res: $_result');
}
}
@override
Widget build(BuildContext context) {
@ -39,7 +45,12 @@ class AnalyzeViewState extends State<AnalyzeView>
body: Builder(builder: (context) {
return Stack(
children: [
MobileScanner(
Align(
alignment: Alignment.center,
child: Container(
width: MediaQuery.of(context).size.width - 100,
color: Colors.black.withOpacity(0.0),
child: MobileScanner(
controller: controller,
fit: BoxFit.contain,
onDetect: (barcode, args) {
@ -47,12 +58,20 @@ class AnalyzeViewState extends State<AnalyzeView>
setState(() {
this.barcode = barcode.rawValue;
});
if (barcode.rawValue.startsWith('smsto:1922:')) {
List<String> recipents = ['0926381229'];
_sendSMS('test2', recipents);
String msg = barcode.rawValue.toLowerCase();
if (msg.startsWith(prefix)) {
List<String> recipents = ['1922'];
msg = msg.substring(prefix.length);
if (peopleCount > 1) {
msg += ' +${peopleCount.toInt()}';
}
_sendSMS(msg, recipents);
}
}
}),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
@ -62,6 +81,7 @@ class AnalyzeViewState extends State<AnalyzeView>
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: SizedBox(
@ -69,13 +89,14 @@ class AnalyzeViewState extends State<AnalyzeView>
height: 80,
child: FittedBox(
child: Slider(
value: number,
value: peopleCount,
min: 1,
max: 10,
label: 'Count $number',
divisions: 9,
label: 'People: ${peopleCount.toInt()}',
onChanged: (v) {
setState(() {
number = v.toInt().toDouble();
peopleCount = v;
});
}),
),
@ -107,7 +128,7 @@ class AnalyzeViewState extends State<AnalyzeView>
),
Center(
child: SizedBox(
width: MediaQuery.of(context).size.width - 120,
width: MediaQuery.of(context).size.width - 220,
height: 50,
child: FittedBox(
child: Text(
@ -115,7 +136,7 @@ class AnalyzeViewState extends State<AnalyzeView>
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
.headline4!
.headlineSmall!
.copyWith(color: Colors.white),
),
),