mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-25 01:05:36 +00:00
refactor: split app wrapper from focused example code (multi-file apps)
Convert 17 multi-file apps to the validated pattern: lib/main.dart keeps only the MaterialApp bootstrap; a new lib/example.dart holds the full entry screen and focused example code, importing existing supporting files (screens/, tabs/, services/, models/, widgets/, utils/). Apps: analytics_integration, animation_example, biometrics, bottom_sheet, custom_home_drawer, google_signin, grid_layout, handling_routes, image_editor, scan_qr_code, statless_counter_app, using_bottom_nav_bar, using_custom_fonts, using_listview, using_listwheelscrollview, using_platform_adaptive, view_pdf_file
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import 'package:scan_qr_code/utils/qr_code_scanner.dart';
|
||||
import 'package:scan_qr_code/utils/scanner_box_border_painter.dart';
|
||||
import 'package:scan_qr_code/example.dart';
|
||||
|
||||
void main() => runApp(const MyApp());
|
||||
|
||||
@@ -13,82 +10,7 @@ class MyApp extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return const MaterialApp(
|
||||
title: 'Code Scanner',
|
||||
home: MyHomePage(title: 'Code Scanner Demo'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
final MobileScannerController _mobileScannerController =
|
||||
MobileScannerController();
|
||||
late void Function(BarcodeCapture) _onDetect;
|
||||
bool _isScanning = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_onDetect = (BarcodeCapture capture) {
|
||||
_mobileScannerController.stop();
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Code info'),
|
||||
content: Text(
|
||||
capture.barcodes.first.rawValue?.trim() ?? 'No data found',
|
||||
textAlign: TextAlign.center),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('OK'))
|
||||
],
|
||||
);
|
||||
}).then((value) {
|
||||
_mobileScannerController.start();
|
||||
setState(() {
|
||||
_isScanning = true;
|
||||
});
|
||||
});
|
||||
|
||||
setState(() {
|
||||
_isScanning = false;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(widget.title)),
|
||||
body: Center(
|
||||
child: SizedBox.square(
|
||||
dimension: MediaQuery.of(context).size.width - 48.0,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(
|
||||
2.5), // Required otherwise side edges hides under outside padding
|
||||
child: CustomPaint(
|
||||
foregroundPainter: ScannerBoxBorderPainter(
|
||||
borderColor: _isScanning ? Colors.black : Colors.green),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(
|
||||
2.5), // Required otherwise scanner hides under side edges
|
||||
child: QRCodeScanner(
|
||||
mobileScannerController: _mobileScannerController,
|
||||
onDetect: _onDetect),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
home: Example(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user