pacote_sc 0.0.4 pacote_sc: ^0.0.4 copied to clipboard
A new Flutter package project.
import 'package:example/ads_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';
import 'package:pacote_sc/screens/scan_create_screen.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:styled_widget/styled_widget.dart';
import 'package:qrscan/qrscan.dart' as scanner;
class Constants {
static final String ADMOB_BANNER_ID =
BannerAd.testAdUnitId; // ADMOB_BANNER_ID
static final String ADMOB_INTERSTITIAL_ID =
InterstitialAd.testAdUnitId; // ADMOB_INTERSTITIAL_ID
static final String FACE_BANNER_ID = ''; // FACE_BANNER_ID
static final String FACE_INTERSTITIAL_ID = ''; // FACE_INTERSTITIAL_ID
}
void main() {
WidgetsFlutterBinding.ensureInitialized();
MobileAds.instance.initialize();
// ADMOB_INSTANCE
// FACE_INSTANCE
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((_) {
runApp(MeuApp());
});
}
final startappId = '';
final admobBId = 'ca-app-pub-3940256099942544/6300978111';
final admobIId = 'ca-app-pub-3940256099942544/1033173712';
final colorPrimary = Colors.green;
class AppController extends GetxController {
final qrCodeString = ''.obs;
getQrCodeString() async {
scanner.scan().then((cameraScanResult) {
debugPrint('string $cameraScanResult');
if (cameraScanResult != null) qrCodeString.value = cameraScanResult;
});
}
@override
void onInit() {
super.onInit();
}
}
class MeuApp extends StatelessWidget {
final Color colorPrimary = Colors.black;
MeuApp();
final controller = Get.put(AppController());
final adsController = Get.put(AdsController());
Future<Widget> _cameraButton() async {
return MaterialButton(
onPressed: () {
adsController.showAdInterstitial(() async {
var status = await Permission.camera.status;
switch (status) {
case PermissionStatus.granted:
controller.getQrCodeString();
break;
default:
bool isShow = await Permission.camera.shouldShowRequestRationale;
if (isShow)
await Permission.camera.request();
else
Get.defaultDialog(
title: 'Camera Permission',
buttonColor: colorPrimary,
confirmTextColor: Colors.white,
cancelTextColor: Colors.black,
middleText:
'This app needs camera access for the QR code reader.',
textCancel: 'Deny',
textConfirm: 'Open Settings',
onConfirm: () => openAppSettings(),
);
}
});
},
child: <Widget>[
Icon(
Icons.camera,
size: 48,
),
Text('Scan QR Code').padding(vertical: 4),
]
.toColumn()
.padding(
vertical: 16,
horizontal: 16,
)
.padding(
vertical: 4,
),
);
}
@override
Widget build(BuildContext context) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.black,
),
home: Scaffold(
appBar: AppBar(
title: Text('Scan & Reader - QR Code'),
),
body: SingleChildScrollView(
child: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'How do you want to start?',
style: Get.theme.textTheme.headline5,
),
),
Divider(),
<Widget>[
FutureBuilder(
future: _cameraButton(),
builder: (_, AsyncSnapshot<Widget> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Center(child: Text('Aguardando Permissão'));
default:
return snapshot.data!;
}
}),
MaterialButton(
onPressed: () {
adsController.showAdInterstitial(() {
Get.to(
() => ScanCreateScreen(colorPrimary: colorPrimary),
);
});
},
child: <Widget>[
Icon(
Icons.qr_code_2,
size: 48,
),
Text('Create QR Code').padding(vertical: 4),
].toColumn().padding(vertical: 4).padding(vertical: 4),
)
].toRow(mainAxisAlignment: MainAxisAlignment.spaceAround),
SizedBox(height: 12),
Obx(() => AnimatedContainer(
duration: Duration(milliseconds: 1200),
child: controller.qrCodeString.value.length > 0
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Card(
elevation: 6,
child: Column(
children: [
Padding(
padding:
const EdgeInsets.only(right: 8, left: 8),
child: Row(
children: [
Text(
'QR Code content:',
style: Get.textTheme.subtitle1,
textAlign: TextAlign.left,
),
Spacer(),
TextButton.icon(
onPressed: () {
controller.qrCodeString.value = '';
},
icon: Icon(Icons.close, size: 18),
label: Text("Close Card"),
)
],
),
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8.0),
child: Container(
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(4),
),
width: double.maxFinite,
margin: EdgeInsets.only(),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
controller.qrCodeString.value,
maxLines: 3,
style: Get.textTheme.bodyText1,
),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8.0,
vertical: 4,
),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: [
OutlinedButton.icon(
onPressed: () {
// Respond to button press
},
icon: Icon(Icons.copy, size: 18),
label: Text("Copy"),
),
OutlinedButton.icon(
onPressed: () {
// Respond to button press
},
icon: Icon(Icons.open_in_browser,
size: 18),
label: Text("Open Browser"),
),
OutlinedButton.icon(
onPressed: () {
// Respond to button press
},
icon: Icon(Icons.share, size: 18),
label: Text("Share"),
)
],
),
),
],
),
),
)
: Container(width: 0, height: 0),
)),
SizedBox(height: 12),
adsController.adBannerContainer,
].toColumn(),
),
),
);
}
}