Skip to content

Commit

Permalink
* upgrade: example support null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
pdliuw committed May 12, 2021
1 parent 6930f27 commit ec0056d
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 113 deletions.
12 changes: 6 additions & 6 deletions example/lib/app_barcode_scanner_widget.dart
Expand Up @@ -2,16 +2,16 @@ import 'package:ai_barcode/ai_barcode.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

String _label;
Function(String result) _resultCallback;
late String _label;
late Function(String result) _resultCallback;

///
/// AppBarcodeScannerWidget
class AppBarcodeScannerWidget extends StatefulWidget {
///
///
AppBarcodeScannerWidget.defaultStyle({
Function(String result) resultCallback,
Function(String result)? resultCallback,
String label = '单号',
}) {
_resultCallback = resultCallback ?? (String result) {};
Expand Down Expand Up @@ -124,10 +124,10 @@ class _BarcodePermissionWidgetState extends State<_BarcodePermissionWidget> {
}

class _BarcodeInputWidget extends StatefulWidget {
ValueChanged<String> _changed;
late ValueChanged<String> _changed;

_BarcodeInputWidget.defaultStyle({
ValueChanged<String> changed,
required ValueChanged<String> changed,
}) {
_changed = changed;
}
Expand Down Expand Up @@ -191,7 +191,7 @@ class _BarcodeScannerWidget extends StatefulWidget {
}

class _AppBarcodeScannerWidgetState extends State<_BarcodeScannerWidget> {
ScannerController _scannerController;
late ScannerController _scannerController;

@override
void initState() {
Expand Down
8 changes: 4 additions & 4 deletions example/lib/creator_page.dart
Expand Up @@ -16,8 +16,8 @@ class CreatorPage extends StatefulWidget {
class _CreatorState extends State<CreatorPage> {
String _qrCodeOfInput = "请输入二维码信息";

CreatorController _creatorController;
TextEditingController _textEditingController;
CreatorController? _creatorController;
TextEditingController? _textEditingController;

@override
void initState() {
Expand Down Expand Up @@ -72,7 +72,7 @@ class _CreatorState extends State<CreatorPage> {
onPressed: () {
setState(() {
//update value
_creatorController.updateValue(
_creatorController?.updateValue(
value: _qrCodeOfInput,
);
});
Expand All @@ -99,7 +99,7 @@ class _CreatorState extends State<CreatorPage> {
),
margin: EdgeInsets.all(40),
child: PlatformAiBarcodeCreatorWidget(
creatorController: _creatorController,
creatorController: _creatorController!,
initialValue: "$_qrCodeOfInput",
),
),
Expand Down
70 changes: 39 additions & 31 deletions example/lib/main.dart
@@ -1,6 +1,7 @@
import 'package:ai_barcode_example/full_screen_scanner_page.dart';
import 'package:ai_barcode_example/task_next_page.dart';
import 'package:ai_barcode_example/testing_page.dart';
import 'package:air_design/air_design.dart';
import 'package:airoute/airoute.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -44,38 +45,45 @@ class _AppState extends State<App> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
MaterialButton(
onPressed: () {
//跳转页面
Airoute.pushNamed(
routeName: "/TestingPage",
);
},
textColor: Colors.white,
color: Colors.blue,
child: Text("Testing Web feature"),
Expanded(
child: AppCardOutlinedStyleWidget.defaultStyle(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MaterialButton(
onPressed: () {
//跳转页面=扫描二维码
Airoute.pushNamed(
routeName: "/SelectScannerStylePage",
);
},
textColor: Colors.white,
color: Colors.blue,
child: Text("Scan 1D barcode/QR code"),
),
],
),
),
),
MaterialButton(
onPressed: () {
//跳转页面=扫描二维码
Airoute.pushNamed(
routeName: "/SelectScannerStylePage",
);
},
textColor: Colors.white,
color: Colors.blue,
child: Text("Scan 1D barcode/QR code"),
),
MaterialButton(
onPressed: () {
//跳转页面=生成二维码
Airoute.pushNamed(
routeName: "/CreatorPage",
);
},
textColor: Colors.white,
color: Colors.blue,
child: Text("Create QR code"),
Expanded(
child: AppCardOutlinedStyleWidget.defaultStyle(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MaterialButton(
onPressed: () {
//跳转页面=生成二维码
Airoute.pushNamed(
routeName: "/CreatorPage",
);
},
textColor: Colors.white,
color: Colors.blue,
child: Text("Create QR code"),
),
],
),
),
),
],
),
Expand Down
16 changes: 8 additions & 8 deletions example/lib/testing_page.dart
Expand Up @@ -11,14 +11,14 @@ class TestingPage extends StatefulWidget {
}

class _TestingState extends State<TestingPage> {
ScannerController _scannerController;
ScannerController? _scannerController;

@override
void initState() {
super.initState();
_scannerController = ScannerController(scannerResult: (result) {
//关闭识别
_scannerController.stopCameraPreview();
_scannerController?.stopCameraPreview();
//提示信息
Airoute.push(
route: AwesomeMessageRoute(
Expand All @@ -29,7 +29,7 @@ class _TestingState extends State<TestingPage> {
),
);
//打开识别
_scannerController.startCameraPreview();
_scannerController?.startCameraPreview();
});
}

Expand All @@ -40,7 +40,7 @@ class _TestingState extends State<TestingPage> {
}

_startPreview() async {
String result = await _scannerController.startCameraPreview();
String result = await _scannerController?.startCameraPreview();
}

@override
Expand All @@ -54,7 +54,7 @@ class _TestingState extends State<TestingPage> {
children: <Widget>[
MaterialButton(
onPressed: () {
_scannerController.startCamera();
_scannerController?.startCamera();
},
textColor: Colors.white,
color: Colors.blue,
Expand All @@ -71,7 +71,7 @@ class _TestingState extends State<TestingPage> {
MaterialButton(
onPressed: () {
//停止相机预览
_scannerController.stopCameraPreview();
_scannerController?.stopCameraPreview();
},
textColor: Colors.white,
color: Colors.blue,
Expand All @@ -80,7 +80,7 @@ class _TestingState extends State<TestingPage> {
MaterialButton(
onPressed: () {
//释放相机
_scannerController.stopCamera();
_scannerController?.stopCamera();
},
textColor: Colors.white,
color: Colors.blue,
Expand All @@ -90,7 +90,7 @@ class _TestingState extends State<TestingPage> {
width: 750,
height: 750,
child: PlatformAiBarcodeScannerWidget(
platformScannerController: _scannerController,
platformScannerController: _scannerController!,
),
),
],
Expand Down

0 comments on commit ec0056d

Please sign in to comment.