Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
pdliuw committed Mar 27, 2020
1 parent d69f32f commit 18ade16
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
4 changes: 0 additions & 4 deletions lib/ai_barcode_web_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ class AiBarcodeCreatorWebPlugin extends AiBarcodeCreatorPlatform {
);

return qrImage;
// return HtmlElementView(
// key: UniqueKey(),
// viewType: AiBarcodePlatform.viewIdOfCreator,
// );
}

@override
Expand Down
5 changes: 5 additions & 0 deletions lib/src/ai_barcode_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,15 @@ class ScannerController {
class PlatformAiBarcodeCreatorWidget extends StatefulWidget {
CreatorController _creatorController;
String _initialValue;
String _unsupportedDescription;
PlatformAiBarcodeCreatorWidget({
@required CreatorController creatorController,
@required String initialValue,
String unsupportedDescription,
}) {
_creatorController = creatorController;
_initialValue = initialValue;
_unsupportedDescription = unsupportedDescription;
}
@override
State<StatefulWidget> createState() {
Expand All @@ -167,6 +170,8 @@ class _PlatformAiBarcodeCreatorState
void initState() {
super.initState();
//create
AiBarcodeCreatorPlatform.instance.unsupportedPlatformDescription =
widget._unsupportedDescription;
AiBarcodeCreatorPlatform.instance.initialValueOfCreator =
widget._initialValue;
AiBarcodeCreatorPlatform.instance.addListener(_creatorCreatedCallback);
Expand Down
27 changes: 26 additions & 1 deletion lib/src/creator/ai_barcode_mobile_creator_plugin.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:qr_flutter/qr_flutter.dart';

import '../ai_barcode_platform_interface.dart';
import 'ai_barcode_platform_creator_interface.dart';
Expand Down Expand Up @@ -46,8 +47,32 @@ class AiBarcodeMobileCreatorPlugin extends AiBarcodeCreatorPlatform {
AiBarcodeCreatorPlatform.instance.initialValueOfCreator);
},
);
} else if (targetPlatform == TargetPlatform.macOS) {
QrImage qrImage = QrImage(
data: AiBarcodeCreatorPlatform.instance.initialValueOfCreator,
version: QrVersions.auto,
size: 200.0,
);
return qrImage;
} else if (targetPlatform == TargetPlatform.windows) {
QrImage qrImage = QrImage(
data: AiBarcodeCreatorPlatform.instance.initialValueOfCreator,
version: QrVersions.auto,
size: 200.0,
);
return qrImage;
} else {
return Text("Unsupported platform!");
return Center(
child: Text(
unsupportedPlatformDescription,
),
);
}
}

@override
updateQRCodeValue(String value) {
AiBarcodeCreatorPlatform.instance.initialValueOfCreator = value;
notifyListeners();
}
}
12 changes: 12 additions & 0 deletions lib/src/creator/ai_barcode_platform_creator_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ abstract class AiBarcodeCreatorPlatform extends ChangeNotifier
_initialValueOfCreator = initialValue;
}

String _unsupportedPlatformDescription =
"Unsupported platforms, working hard to support";

String get unsupportedPlatformDescription => _unsupportedPlatformDescription;

set unsupportedPlatformDescription(String text) {
if (text == null || text.isEmpty) {
return;
}
_unsupportedPlatformDescription = text;
}

///
/// Instance update
static set instance(AiBarcodeCreatorPlatform instance) {
Expand Down
7 changes: 1 addition & 6 deletions lib/src/scanner/ai_barcode_mobile_scanner_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ import '../ai_barcode_platform_interface.dart';
import 'ai_barcode_platform_scanner_interface.dart';

///
/// AiBarcodeMobilePlugin
/// AiBarcodeMobileScannerPlugin
class AiBarcodeMobileScannerPlugin extends AiBarcodeScannerPlatform {
@override
Widget buildScannerView(BuildContext context) {
return _cameraView(context);
}

// @override
// Widget buildCreatorView(BuildContext context) {
// return _barcodeCreator(context: context);
// }

/// Barcode reader widget
///
/// Support android and ios platform barcode reader
Expand Down

0 comments on commit 18ade16

Please sign in to comment.