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

5729eb498eaeb9c64784fcfc80bbb33b
48197743e3d78b3769f70bac9a76e7e0

+ 42
- 69
lib/main.dart View File

import 'package:barcode_scan/barcode_scan.dart'; import 'package:barcode_scan/barcode_scan.dart';
import 'package:camera/camera.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:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get/route_manager.dart'; import 'package:get/route_manager.dart';
import 'package:rflutter_alert/rflutter_alert.dart';
import 'app.dart'; import 'app.dart';
import 'custom_model/CropPlot.dart';
import 'data/repository/authentication_repository.dart'; import 'data/repository/authentication_repository.dart';
import 'data/repository/repository.dart'; import 'data/repository/repository.dart';
import 'presentation/custom_widgets/widget_utils.dart';


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

textCancel: textCancel, textCancel: textCancel,
confirmTextColor: Colors.white, confirmTextColor: Colors.white,
onConfirm: onConfirm, onConfirm: onConfirm,
onCancel: () {
Get.back();
},
); );
} }



+ 1
- 1
pubspec.lock View File

name: file_picker name: file_picker
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0"
version: "2.0.7"
firebase: firebase:
dependency: transitive dependency: transitive
description: description:

+ 1
- 1
pubspec.yaml View File



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


mime: ^0.9.7 mime: ^0.9.7

Loading…
Cancel
Save