master
UC-HOBA 4 years ago
parent 8458935de4
commit bca3b7e5fb
  1. 5
      android/app/src/main/AndroidManifest.xml
  2. 160
      lib/main.dart
  3. 8
      pubspec.yaml
  4. 2
      test/widget_test.dart

@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.contact_tracing"> package="com.example.contact_tracing">
<application <application
android:label="contact_tracing" android:label="contact_tracing"
android:name="${applicationName}" android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"> android:icon="@mipmap/ic_launcher">
@ -37,5 +37,6 @@
<action android:name="android.intent.action.SENDTO" /> <action android:name="android.intent.action.SENDTO" />
<data android:scheme="smsto" /> <data android:scheme="smsto" />
</intent> </intent>
</queries> </queries>
<uses-permission android:name="android.permission.SEND_SMS"/>
</manifest> </manifest>

@ -1,6 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart'; import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_sms/flutter_sms.dart'; import 'package:flutter_sms/flutter_sms.dart';
void main() { void main() {
@ -11,22 +10,19 @@ class AnalyzeView extends StatefulWidget {
const AnalyzeView({Key? key}) : super(key: key); const AnalyzeView({Key? key}) : super(key: key);
@override @override
_AnalyzeViewState createState() => _AnalyzeViewState(); AnalyzeViewState createState() => AnalyzeViewState();
} }
class _AnalyzeViewState extends State<AnalyzeView> class AnalyzeViewState extends State<AnalyzeView>
with SingleTickerProviderStateMixin { with SingleTickerProviderStateMixin {
String? barcode; String? barcode;
double number = 1;
MobileScannerController controller = MobileScannerController( MobileScannerController controller = MobileScannerController(
torchEnabled: false, torchEnabled: false,
facing: CameraFacing.back, facing: CameraFacing.back,
); );
void launchURL(String url) async {
if (!await launch(url)) throw 'Could not launch $url';
}
void _sendSMS(String message, List<String> recipents) async { void _sendSMS(String message, List<String> recipents) async {
String _result = await sendSMS(message: message, recipients: recipents) String _result = await sendSMS(message: message, recipients: recipents)
.catchError((onError) { .catchError((onError) {
@ -46,85 +42,105 @@ class _AnalyzeViewState extends State<AnalyzeView>
MobileScanner( MobileScanner(
controller: controller, controller: controller,
fit: BoxFit.contain, fit: BoxFit.contain,
// controller: MobileScannerController(
// torchEnabled: true,
// facing: CameraFacing.front,
// ),
onDetect: (barcode, args) { onDetect: (barcode, args) {
if (this.barcode != barcode.rawValue) { if (this.barcode != barcode.rawValue) {
setState(() { setState(() {
this.barcode = barcode.rawValue; this.barcode = barcode.rawValue;
}); });
if (barcode.rawValue.startsWith('smsto')) { if (barcode.rawValue.startsWith('smsto:1922:')) {
//launchURL(barcode.rawValue); List<String> recipents = ['0926381229'];
List<String> recipents = ["0926381229"]; _sendSMS('test2', recipents);
_sendSMS(barcode.rawValue, recipents);
} }
} }
}), }),
Align( Align(
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
child: Container( child: Container(
alignment: Alignment.bottomCenter, alignment: Alignment.bottomCenter,
height: 100, height: 150,
color: Colors.black.withOpacity(0.4), color: Colors.black.withOpacity(0.4),
child: Row( child: Column(
crossAxisAlignment: CrossAxisAlignment.center, children: [
mainAxisAlignment: MainAxisAlignment.spaceEvenly, Row(
children: [ children: [
IconButton( Center(
color: Colors.white, child: SizedBox(
icon: ValueListenableBuilder( width: MediaQuery.of(context).size.width,
valueListenable: controller.torchState, height: 80,
builder: (context, state, child) { child: FittedBox(
switch (state as TorchState) { child: Slider(
case TorchState.off: value: number,
return const Icon(Icons.flash_off, min: 1,
color: Colors.grey); max: 10,
case TorchState.on: label: 'Count $number',
return const Icon(Icons.flash_on, onChanged: (v) {
color: Colors.yellow); setState(() {
} number = v.toInt().toDouble();
}, });
), }),
iconSize: 32.0, ),
onPressed: () => controller.toggleTorch(), ),
),
Center(
child: SizedBox(
width: MediaQuery.of(context).size.width - 120,
height: 50,
child: FittedBox(
child: Text(
barcode ?? 'Scan something!',
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
.headline4!
.copyWith(color: Colors.white),
), ),
), ],
), ),
), Row(
IconButton( crossAxisAlignment: CrossAxisAlignment.center,
color: Colors.white, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
icon: ValueListenableBuilder( children: [
valueListenable: controller.cameraFacingState, IconButton(
builder: (context, state, child) { color: Colors.white,
switch (state as CameraFacing) { icon: ValueListenableBuilder(
case CameraFacing.front: valueListenable: controller.torchState,
return const Icon(Icons.camera_front); builder: (context, state, child) {
case CameraFacing.back: switch (state as TorchState) {
return const Icon(Icons.camera_rear); case TorchState.off:
} return const Icon(Icons.flash_off,
}, color: Colors.grey);
case TorchState.on:
return const Icon(Icons.flash_on,
color: Colors.yellow);
}
},
),
iconSize: 32.0,
onPressed: () => controller.toggleTorch(),
),
Center(
child: SizedBox(
width: MediaQuery.of(context).size.width - 120,
height: 50,
child: FittedBox(
child: Text(
barcode ?? 'Scan something!',
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
.headline4!
.copyWith(color: Colors.white),
),
),
),
),
IconButton(
color: Colors.white,
icon: ValueListenableBuilder(
valueListenable: controller.cameraFacingState,
builder: (context, state, child) {
switch (state as CameraFacing) {
case CameraFacing.front:
return const Icon(Icons.camera_front);
case CameraFacing.back:
return const Icon(Icons.camera_rear);
}
},
),
iconSize: 32.0,
onPressed: () => controller.switchCamera(),
),
],
), ),
iconSize: 32.0, ],
onPressed: () => controller.switchCamera(), )),
),
],
),
),
), ),
// Container( // Container(

@ -1,5 +1,5 @@
name: contact_tracing name: contact_tracing
description: Contect Tracing description: Contact Tracing
# The following line prevents the package from being accidentally published to # The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages. # pub.dev using `flutter pub publish`. This is preferred for private packages.
@ -34,8 +34,12 @@ dependencies:
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
flutter_sms: ^2.3.2
mobile_scanner: ^0.0.3 mobile_scanner: ^0.0.3
flutter_sms: ^2.3.2
# flutter_sms:
# git:
# url: git://github.com/NextFaze/flutter_sms.git
# ref: send-sms-directly
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

@ -13,7 +13,7 @@ import 'package:contact_tracing/main.dart';
void main() { void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async { testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(const MyApp()); //await tester.pumpWidget(const MyApp());
// Verify that our counter starts at 0. // Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);