Browse Source

fix Bug #7347

master
daivph 5 years ago
parent
commit
23aeddc7de
5 changed files with 48 additions and 72 deletions
  1. +1
    -1
      ios/Flutter/.last_build_id
  2. +42
    -69
      lib/main.dart
  3. +3
    -0
      lib/presentation/custom_widgets/widget_utils.dart
  4. +1
    -1
      pubspec.lock
  5. +1
    -1
      pubspec.yaml

+ 1
- 1
ios/Flutter/.last_build_id View File

@@ -1 +1 @@
5729eb498eaeb9c64784fcfc80bbb33b
48197743e3d78b3769f70bac9a76e7e0

+ 42
- 69
lib/main.dart View File

@@ -1,16 +1,13 @@
import 'package:barcode_scan/barcode_scan.dart';
import 'package:camera/camera.dart';
import 'package:farm_tpf/presentation/screens/plot_detail/bloc/plot_detail_bloc.dart';
import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get/route_manager.dart';
import 'package:rflutter_alert/rflutter_alert.dart';
import 'app.dart';
import 'custom_model/CropPlot.dart';
import 'data/repository/authentication_repository.dart';
import 'data/repository/repository.dart';
import 'presentation/custom_widgets/widget_utils.dart';

List<CameraDescription> cameras = [];
Future<void> main() async {
@@ -43,6 +40,7 @@ Future scan(BuildContext context) async {
var _selectedCamera = -1;
var _useAutoFocus = true;
var _autoEnableFlash = false;
var repository = Repository();
try {
var options = ScanOptions(
strings: {
@@ -64,75 +62,50 @@ Future scan(BuildContext context) async {
} else if (result.type == ResultType.Error) {
print("error");
} else {
_showAlertCheckCropCode(context, result.rawContent);
print("show check crop");
_showAlertCheckCropCode(context, result.rawContent, repository);
}
} on PlatformException catch (e) {
var result = ScanResult(
type: ResultType.Error,
format: BarcodeFormat.unknown,
);
print("error: ${e.message}");
}
}

_showAlertCheckCropCode(BuildContext context, String cropCode) {
Alert(
context: context,
title: "",
style: AlertStyle(isCloseButton: false, isOverlayTapDismiss: false),
content: BlocProvider<PlotDetailBloc>(
create: (context) => PlotDetailBloc(repository: Repository())
..add(DataFetched(cropCode: cropCode)),
child: BlocBuilder<PlotDetailBloc, PlotDetailState>(
builder: (context, state) {
if (state is PlotDetailInitial) {
return Center(
child: Text(""),
);
} else if (state is PlotDetailFailure) {
return Center(
child: Column(
children: [
Text("Lô không tồn tại"),
SizedBox(
height: 16,
),
DialogButton(
onPressed: () {
Get.back();
scan(context);
},
child: Text(
"Quét lại",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
],
),
);
} else if (state is PlotDetailSuccess) {
var result = state.ownerItem as CropPlot;
WidgetsBinding.instance.addPostFrameCallback((_) {
Get.back();
Get.to(PlotDetailScreen(
cropId: result.tbCropDTO.id,
initialIndex: 1,
));
});
return Center(child: Text(""));
} else {
return Center(
child: Column(
children: [
CircularProgressIndicator(),
SizedBox(
height: 8,
),
Text("Kiểm tra thông tin lô ....")
],
),
);
}
})),
buttons: []).show();
_showAlertCheckCropCode(
BuildContext context, String cropCode, Repository repository) async {
Get.defaultDialog(
title: "Kiểm tra thông tin lô ....",
middleText: "",
content: CircularProgressIndicator());
try {
await repository
.getPlotDetailByCode(cropCode, page: 1, size: 1)
.then((value) {
print("ok");
if (Get.isDialogOpen) Get.back();
Get.to(PlotDetailScreen(
cropId: value.tbCropDTO.id,
initialIndex: 1,
));
}).catchError((onError) {
Utils.showDialog(
title: "Không tìm thấy lô",
message: "Thử lại với mã tem khác?",
textConfirm: "Thử lại",
textCancel: "Huỷ",
onConfirm: () {
Get.back();
scan(context);
});
});
} catch (e) {
Utils.showDialog(
title: "Không tìm thấy lô",
message: "Thử lại với mã tem khác?",
textConfirm: "Thử lại",
textCancel: "Huỷ",
onConfirm: () {
Get.back();
scan(context);
});
}
}

+ 3
- 0
lib/presentation/custom_widgets/widget_utils.dart View File

@@ -49,6 +49,9 @@ class Utils {
textCancel: textCancel,
confirmTextColor: Colors.white,
onConfirm: onConfirm,
onCancel: () {
Get.back();
},
);
}


+ 1
- 1
pubspec.lock View File

@@ -259,7 +259,7 @@ packages:
name: file_picker
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.0.7"
firebase:
dependency: transitive
description:

+ 1
- 1
pubspec.yaml View File

@@ -43,7 +43,7 @@ dependencies:

camera: ^0.5.8+5
path_provider: ^1.6.14
file_picker: ^2.0.0
file_picker: ^2.0.7
flutter_cache_manager: ^1.4.2

mime: ^0.9.7

Loading…
Cancel
Save