Skip to content

Commit 9db37c7

Browse files
committed
update example
1 parent a9719e8 commit 9db37c7

File tree

4 files changed

+115
-70
lines changed

4 files changed

+115
-70
lines changed

android/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version '1.0'
44
buildscript {
55
repositories {
66
google()
7-
jcenter()
7+
mavenCentral()
88
maven {url 'https://developer.huawei.com/repo/'}
99
}
1010

@@ -16,7 +16,7 @@ buildscript {
1616
rootProject.allprojects {
1717
repositories {
1818
google()
19-
jcenter()
19+
mavenCentral()
2020
maven {url 'https://developer.huawei.com/repo/'}
2121
}
2222
}
@@ -37,7 +37,7 @@ android {
3737
}
3838

3939
dependencies {
40-
implementation('com.journeyapps:zxing-android-embedded:4.1.0') { transitive = false }
40+
implementation('com.journeyapps:zxing-android-embedded:4.3.0') { transitive = false }
4141
implementation 'androidx.appcompat:appcompat:1.2.0'
4242
implementation 'com.google.zxing:core:3.3.0'
4343
// implementation 'com.huawei.hms:scanplus:1.3.1.300'

example/lib/main.dart

Lines changed: 40 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:async';
66
import 'package:flutter/services.dart';
77
import 'package:scan/scan.dart';
88
import 'package:images_picker/images_picker.dart';
9+
import 'package:scan_example/scan.dart';
910

1011
void main() {
1112
runApp(MyApp());
@@ -19,7 +20,6 @@ class MyApp extends StatefulWidget {
1920
class _MyAppState extends State<MyApp> {
2021
String _platformVersion = 'Unknown';
2122

22-
ScanController controller = ScanController();
2323
String qrcode = 'Unknown';
2424

2525
@override
@@ -45,67 +45,47 @@ class _MyAppState extends State<MyApp> {
4545
@override
4646
Widget build(BuildContext context) {
4747
return MaterialApp(
48-
home: Scaffold(
49-
appBar: AppBar(
50-
title: const Text('Plugin example app'),
51-
),
52-
body: Column(
53-
children: [
54-
Text('Running on: $_platformVersion\n'),
55-
Wrap(
56-
children: [
57-
ElevatedButton(
58-
child: Text("toggleTorchMode"),
59-
onPressed: () {
60-
controller.toggleTorchMode();
61-
},
62-
),
63-
ElevatedButton(
64-
child: Text("pause"),
65-
onPressed: () {
66-
controller.pause();
67-
},
68-
),
69-
ElevatedButton(
70-
child: Text("resume"),
71-
onPressed: () {
72-
controller.resume();
73-
},
74-
),
75-
ElevatedButton(
76-
child: Text("parse from image"),
77-
onPressed: () async {
78-
List<Media>? res = await ImagesPicker.pick();
79-
if (res != null) {
80-
String? str = await Scan.parse(res[0].path);
81-
if (str != null) {
82-
setState(() {
83-
qrcode = str;
84-
});
85-
}
86-
}
87-
},
88-
),
89-
],
90-
),
91-
Container(
92-
width: 220,
93-
height: 400,
94-
child: ScanView(
95-
controller: controller,
96-
scanAreaScale: .7,
97-
scanLineColor: Colors.green,
98-
onCapture: (data) {
99-
setState(() {
100-
qrcode = data;
101-
});
102-
},
48+
initialRoute: '/',
49+
routes: {
50+
'/': (context) => Scaffold(
51+
appBar: AppBar(
52+
title: const Text('Plugin example app'),
53+
),
54+
body: Column(
55+
children: [
56+
Text('Running on: $_platformVersion\n'),
57+
Wrap(
58+
children: [
59+
ElevatedButton(
60+
child: Text("parse from image"),
61+
onPressed: () async {
62+
List<Media>? res = await ImagesPicker.pick();
63+
if (res != null) {
64+
String? str = await Scan.parse(res[0].path);
65+
if (str != null) {
66+
setState(() {
67+
qrcode = str;
68+
});
69+
}
70+
}
71+
},
72+
),
73+
ElevatedButton(
74+
child: Text('go scan page'),
75+
onPressed: () {
76+
Navigator.push(context,
77+
MaterialPageRoute(builder: (_) {
78+
return ScanPage();
79+
}));
80+
},
81+
),
82+
],
83+
),
84+
Text('scan result is $qrcode'),
85+
],
10386
),
10487
),
105-
Text('scan result is $qrcode'),
106-
],
107-
),
108-
),
88+
},
10989
);
11090
}
11191
}

example/lib/scan.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:scan/scan.dart';
3+
4+
class ScanPage extends StatelessWidget {
5+
ScanController controller = ScanController();
6+
@override
7+
Widget build(BuildContext context) {
8+
return Scaffold(
9+
body: SafeArea(
10+
top: true,
11+
bottom: true,
12+
child: Stack(
13+
children: [
14+
ScanView(
15+
controller: controller,
16+
scanAreaScale: .7,
17+
scanLineColor: Colors.green,
18+
onCapture: (data) {
19+
Navigator.push(context, MaterialPageRoute(
20+
builder: (BuildContext context) {
21+
return Scaffold(
22+
appBar: AppBar(
23+
title: Text('scan result'),
24+
),
25+
body: Center(
26+
child: Text(data),
27+
),
28+
);
29+
},
30+
)).then((value) {
31+
controller.resume();
32+
});
33+
},
34+
),
35+
Positioned(
36+
bottom: 0,
37+
child: Row(
38+
children: [
39+
ElevatedButton(
40+
child: Text("toggleTorchMode"),
41+
onPressed: () {
42+
controller.toggleTorchMode();
43+
},
44+
),
45+
ElevatedButton(
46+
child: Text("pause"),
47+
onPressed: () {
48+
controller.pause();
49+
},
50+
),
51+
ElevatedButton(
52+
child: Text("resume"),
53+
onPressed: () {
54+
controller.resume();
55+
},
56+
),
57+
],
58+
),
59+
),
60+
],
61+
),
62+
),
63+
);
64+
}
65+
}

example/pubspec.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
name: async
88
url: "https://pub.flutter-io.cn"
99
source: hosted
10-
version: "2.8.1"
10+
version: "2.8.2"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
@@ -21,7 +21,7 @@ packages:
2121
name: characters
2222
url: "https://pub.flutter-io.cn"
2323
source: hosted
24-
version: "1.1.0"
24+
version: "1.2.0"
2525
charcode:
2626
dependency: transitive
2727
description:
@@ -73,7 +73,7 @@ packages:
7373
name: matcher
7474
url: "https://pub.flutter-io.cn"
7575
source: hosted
76-
version: "0.12.10"
76+
version: "0.12.11"
7777
meta:
7878
dependency: transitive
7979
description:
@@ -94,7 +94,7 @@ packages:
9494
path: ".."
9595
relative: true
9696
source: path
97-
version: "1.4.3"
97+
version: "1.5.0"
9898
sky_engine:
9999
dependency: transitive
100100
description: flutter
@@ -141,7 +141,7 @@ packages:
141141
name: test_api
142142
url: "https://pub.flutter-io.cn"
143143
source: hosted
144-
version: "0.4.2"
144+
version: "0.4.3"
145145
typed_data:
146146
dependency: transitive
147147
description:
@@ -155,7 +155,7 @@ packages:
155155
name: vector_math
156156
url: "https://pub.flutter-io.cn"
157157
source: hosted
158-
version: "2.1.0"
158+
version: "2.1.1"
159159
sdks:
160-
dart: ">=2.12.0 <3.0.0"
160+
dart: ">=2.14.0 <3.0.0"
161161
flutter: ">=1.12.13+hotfix.5"

0 commit comments

Comments
 (0)