You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

212 lines
8.2 KiB

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:mobile_scanner/mobile_scanner.dart';
import 'package:flutter_sms/flutter_sms.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:flutter_vibrate/flutter_vibrate.dart';
void main() {
runApp(const AnalyzeView());
}
class AnalyzeView extends StatefulWidget {
const AnalyzeView({Key? key}) : super(key: key);
@override
AnalyzeViewState createState() => AnalyzeViewState();
}
class AnalyzeViewState extends State<AnalyzeView>
with SingleTickerProviderStateMixin {
String? barcode;
double peopleCount = 1;
final String prefix = 'smsto:1922:';
MobileScannerController controller = MobileScannerController(
torchEnabled: false,
facing: CameraFacing.back,
);
void _sendSMS(String message, List<String> recipents) async {
if (await Vibrate.canVibrate) {
Vibrate.vibrate();
}
var status = await Permission.sms.status;
if (status.isDenied) {
Map<Permission, PermissionStatus> statuses = await [
Permission.sms,
].request();
}
String _result =
await sendSMS(message: message, recipients: recipents, sendDirect: true)
.catchError((onError) {
if (kDebugMode) {
print('sms err: $onError');
}
});
if (kDebugMode) {
print('sms res: $_result');
}
await sendSMS(message: '', recipients: recipents, sendDirect: false);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black,
body: Builder(builder: (context) {
return Stack(
children: [
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) {
if (this.barcode != barcode.rawValue) {
setState(() {
this.barcode = barcode.rawValue;
});
String msg = barcode.rawValue.toLowerCase();
if (msg.startsWith(prefix)) {
List<String> recipents = ['1922'];
msg = msg.substring(prefix.length);
if (peopleCount > 1) {
msg += ' +${peopleCount.toInt() - 1}';
}
_sendSMS(msg, recipents);
}
}
}),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
alignment: Alignment.bottomCenter,
height: 150,
color: Colors.black.withOpacity(0.4),
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Center(
child: SizedBox(
width: MediaQuery.of(context).size.width,
height: 80,
child: FittedBox(
child: Slider(
value: peopleCount,
min: 1,
max: 10,
divisions: 9,
label: 'People: ${peopleCount.toInt()}',
onChanged: (v) {
setState(() {
peopleCount = v;
});
}),
),
),
),
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
color: Colors.white,
icon: ValueListenableBuilder(
valueListenable: controller.torchState,
builder: (context, state, child) {
switch (state as TorchState) {
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 - 220,
height: 50,
child: FittedBox(
child: Text(
barcode ?? 'Scan something!',
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
.headlineSmall!
.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(),
),
],
),
],
)),
),
// Container(
// alignment: Alignment.bottomCenter,
// margin: EdgeInsets.only(bottom: 80.0),
// child: IconButton(
// icon: ValueListenableBuilder(
// valueListenable: cameraController.torchState,
// builder: (context, state, child) {
// final color =
// state == TorchState.off ? Colors.grey : Colors.white;
// return Icon(Icons.bolt, color: color);
// },
// ),
// iconSize: 32.0,
// onPressed: () => cameraController.torch(),
// ),
// ),
],
);
}),
),
);
}
@override
void dispose() {
// cameraController.dispose();
super.dispose();
}
void display(Barcode barcode) {
Navigator.of(context).popAndPushNamed('display', arguments: barcode);
}
}