printer setting release
parent
4140e7c2fe
commit
caa8e3ca12
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'package:satu/core/utils/utils_parse.dart';
|
||||||
|
|
||||||
/// id : 6
|
/// id : 6
|
||||||
/// category_id : 4
|
/// category_id : 4
|
||||||
/// name : "KENT SILVER"
|
/// name : "KENT SILVER"
|
||||||
|
|
@ -17,7 +19,7 @@ class GoodResponse {
|
||||||
int? articul;
|
int? articul;
|
||||||
int? price;
|
int? price;
|
||||||
int? optPrice;
|
int? optPrice;
|
||||||
int? basePrice;
|
double? basePrice;
|
||||||
int? divisible;
|
int? divisible;
|
||||||
String? updatedAt;
|
String? updatedAt;
|
||||||
|
|
||||||
|
|
@ -30,7 +32,7 @@ class GoodResponse {
|
||||||
goodResponseBean.articul = map['articul'] as int;
|
goodResponseBean.articul = map['articul'] as int;
|
||||||
goodResponseBean.price = map['price'] as int;
|
goodResponseBean.price = map['price'] as int;
|
||||||
goodResponseBean.optPrice = map['opt_price'] as int;
|
goodResponseBean.optPrice = map['opt_price'] as int;
|
||||||
goodResponseBean.basePrice = map['base_price'] as int;
|
goodResponseBean.basePrice = cast<double>(map['base_price']);
|
||||||
goodResponseBean.divisible = map['divisible'] as int;
|
goodResponseBean.divisible = map['divisible'] as int;
|
||||||
goodResponseBean.updatedAt = map['updated_at'] as String;
|
goodResponseBean.updatedAt = map['updated_at'] as String;
|
||||||
return goodResponseBean;
|
return goodResponseBean;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,73 @@
|
||||||
|
|
||||||
|
import 'package:satu/core/utils/utils_parse.dart';
|
||||||
|
|
||||||
|
class PrinterConst {
|
||||||
|
PrinterConst();
|
||||||
|
static const String paperSize58mm = '58mm';
|
||||||
|
static const String paperSize80mm = '80mm';
|
||||||
|
static const String encodingCP866 = 'CP866';
|
||||||
|
static const String encodingCP1251 = 'Windows-1251';
|
||||||
|
static const String encodingBigEncoding = 'BigEncoding';
|
||||||
|
}
|
||||||
|
|
||||||
|
class PrinterSetting {
|
||||||
|
|
||||||
|
PrinterSetting({
|
||||||
|
this.device,
|
||||||
|
this.encoding = PrinterConst.encodingCP866,
|
||||||
|
this.paperSize = PrinterConst.paperSize58mm,
|
||||||
|
});
|
||||||
|
|
||||||
|
PrinterDevice? device;
|
||||||
|
String? encoding ;
|
||||||
|
String? paperSize ;
|
||||||
|
|
||||||
|
dynamic toMap() {
|
||||||
|
return {
|
||||||
|
'device': device != null ? device!.toMap() : null,
|
||||||
|
'encoding': encoding,
|
||||||
|
'paperSize': paperSize,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory PrinterSetting.fromMap(dynamic map) {
|
||||||
|
return PrinterSetting(
|
||||||
|
device: map['device']!=null ? PrinterDevice.fromMap(map['device']) : null,
|
||||||
|
encoding: cast<String>(map['encoding']),
|
||||||
|
paperSize: cast<String>(map['paperSize']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class PrinterDevice {
|
||||||
|
String? name;
|
||||||
|
String? address;
|
||||||
|
int? type = 0;
|
||||||
|
bool? connected = false;
|
||||||
|
|
||||||
|
PrinterDevice({
|
||||||
|
this.name,
|
||||||
|
this.address,
|
||||||
|
this.type,
|
||||||
|
this.connected,
|
||||||
|
});
|
||||||
|
|
||||||
|
dynamic toMap() {
|
||||||
|
return {
|
||||||
|
'name': name,
|
||||||
|
'address': address,
|
||||||
|
'type': type,
|
||||||
|
'connected': connected,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory PrinterDevice.fromMap(dynamic map) {
|
||||||
|
return PrinterDevice(
|
||||||
|
name: cast<String>(map['name']),
|
||||||
|
address: cast<String>(map['address']),
|
||||||
|
type: cast<int>(map['type']),
|
||||||
|
connected: cast<bool>(map['connected']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:logger/logger.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
import 'package:redux/redux.dart';
|
||||||
|
import 'package:redux_thunk/redux_thunk.dart';
|
||||||
|
import 'package:satu/core/entity/category_entity.dart';
|
||||||
|
import 'package:satu/core/entity/goods_entity.dart';
|
||||||
|
import 'package:satu/core/entity/transaction_entity.dart';
|
||||||
|
import 'package:satu/core/entity/transaction_rec_entity.dart';
|
||||||
|
import 'package:satu/core/models/entity_data/transaction_data.dart';
|
||||||
|
import 'package:satu/core/models/flow/dao/product_dao.dart';
|
||||||
|
import 'package:satu/core/models/flow/dao/transaction_dao.dart';
|
||||||
|
import 'package:satu/core/models/flow/transaction_state.dart';
|
||||||
|
import 'package:satu/core/models/settings/printer_setting.dart';
|
||||||
|
import 'package:satu/core/redux/state/journal_state.dart';
|
||||||
|
import 'package:satu/core/redux/state/sell_state.dart';
|
||||||
|
import 'package:satu/core/redux/state/setting_state.dart';
|
||||||
|
import 'package:satu/core/services/db_service.dart';
|
||||||
|
import 'package:satu/core/utils/locator.dart';
|
||||||
|
import 'package:satu/core/utils/logger.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
|
import '../store.dart';
|
||||||
|
|
||||||
|
@immutable
|
||||||
|
class SetSettingStateAction {
|
||||||
|
const SetSettingStateAction(this.settingState);
|
||||||
|
|
||||||
|
final SettingState settingState;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Logger log = getLogger('SetSettingStateAction');
|
||||||
|
|
||||||
|
|
||||||
|
ThunkAction<AppState> selectBluetoothDevice(PrinterDevice device) {
|
||||||
|
return (Store<AppState> store) async {
|
||||||
|
final PrinterSetting? setting = store.state.settingState?.printer;
|
||||||
|
if(setting != null) {
|
||||||
|
setting.device = device;
|
||||||
|
store.dispatch(SetSettingStateAction(SettingState(printer: setting)));
|
||||||
|
log.i('device with name ${device.name} added');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ThunkAction<AppState> setPaperSize(String size) {
|
||||||
|
return (Store<AppState> store) async {
|
||||||
|
final PrinterSetting? setting = store.state.settingState?.printer;
|
||||||
|
if(setting != null) {
|
||||||
|
setting.paperSize = size;
|
||||||
|
store.dispatch(SetSettingStateAction(SettingState(printer: setting)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ThunkAction<AppState> setEncodingPrint(String encoding) {
|
||||||
|
return (Store<AppState> store) async {
|
||||||
|
final PrinterSetting? setting = store.state.settingState?.printer;
|
||||||
|
if(setting != null) {
|
||||||
|
setting.encoding = encoding;
|
||||||
|
store.dispatch(SetSettingStateAction(SettingState(printer: setting)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
import 'package:satu/core/redux/actions/journal_actions.dart';
|
||||||
|
import 'package:satu/core/redux/actions/sell_actions.dart';
|
||||||
|
import 'package:satu/core/redux/actions/setting_actions.dart';
|
||||||
|
import 'package:satu/core/redux/actions/user_actions.dart';
|
||||||
|
import 'package:satu/core/redux/state/journal_state.dart';
|
||||||
|
import 'package:satu/core/redux/state/sell_state.dart';
|
||||||
|
import 'package:satu/core/redux/state/setting_state.dart';
|
||||||
|
import 'package:satu/core/redux/state/user_state.dart';
|
||||||
|
|
||||||
|
SettingState settingReducer(
|
||||||
|
SettingState prevState, SetSettingStateAction action) {
|
||||||
|
final SettingState payload = action.settingState;
|
||||||
|
return prevState.copyWith(printer: payload.printer);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
import 'package:satu/core/models/flow/dao/transaction_dao.dart';
|
||||||
|
import 'package:satu/core/models/settings/printer_setting.dart';
|
||||||
|
|
||||||
|
@immutable
|
||||||
|
class SettingState {
|
||||||
|
const SettingState({this.printer});
|
||||||
|
|
||||||
|
factory SettingState.initial(SettingState? settingState) =>
|
||||||
|
SettingState(printer: settingState?.printer ?? PrinterSetting());
|
||||||
|
|
||||||
|
final PrinterSetting? printer;
|
||||||
|
|
||||||
|
SettingState copyWith({PrinterSetting? printer}) {
|
||||||
|
return SettingState(printer: printer ?? this.printer);
|
||||||
|
}
|
||||||
|
|
||||||
|
dynamic toMap() {
|
||||||
|
return {
|
||||||
|
'printer': printer !=null ? printer!.toMap() : null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory SettingState.fromMap(dynamic map) {
|
||||||
|
if (map == null) return SettingState.initial(null);
|
||||||
|
return SettingState(
|
||||||
|
printer: map['printer'] != null
|
||||||
|
? PrinterSetting.fromMap(map['printer'])
|
||||||
|
: null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,13 +6,16 @@ import 'package:redux_persist/redux_persist.dart';
|
||||||
import 'package:satu/core/redux/actions/journal_actions.dart';
|
import 'package:satu/core/redux/actions/journal_actions.dart';
|
||||||
import 'package:satu/core/redux/actions/nav_actions.dart';
|
import 'package:satu/core/redux/actions/nav_actions.dart';
|
||||||
import 'package:satu/core/redux/actions/sell_actions.dart';
|
import 'package:satu/core/redux/actions/sell_actions.dart';
|
||||||
|
import 'package:satu/core/redux/actions/setting_actions.dart';
|
||||||
import 'package:satu/core/redux/reducers/journal_reducer.dart';
|
import 'package:satu/core/redux/reducers/journal_reducer.dart';
|
||||||
import 'package:satu/core/redux/reducers/nav_reducer.dart';
|
import 'package:satu/core/redux/reducers/nav_reducer.dart';
|
||||||
import 'package:satu/core/redux/reducers/sell_reducer.dart';
|
import 'package:satu/core/redux/reducers/sell_reducer.dart';
|
||||||
|
import 'package:satu/core/redux/reducers/setting_reducer.dart';
|
||||||
import 'package:satu/core/redux/reducers/user_reducer.dart';
|
import 'package:satu/core/redux/reducers/user_reducer.dart';
|
||||||
import 'package:satu/core/redux/state/journal_state.dart';
|
import 'package:satu/core/redux/state/journal_state.dart';
|
||||||
import 'package:satu/core/redux/state/nav_state.dart';
|
import 'package:satu/core/redux/state/nav_state.dart';
|
||||||
import 'package:satu/core/redux/state/sell_state.dart';
|
import 'package:satu/core/redux/state/sell_state.dart';
|
||||||
|
import 'package:satu/core/redux/state/setting_state.dart';
|
||||||
import 'package:satu/core/redux/state/user_state.dart';
|
import 'package:satu/core/redux/state/user_state.dart';
|
||||||
|
|
||||||
import 'actions/user_actions.dart';
|
import 'actions/user_actions.dart';
|
||||||
|
|
@ -20,21 +23,20 @@ import 'actions/user_actions.dart';
|
||||||
//reducer context
|
//reducer context
|
||||||
AppState appReducer(AppState state, dynamic action) {
|
AppState appReducer(AppState state, dynamic action) {
|
||||||
if (action is SetUserStateAction) {
|
if (action is SetUserStateAction) {
|
||||||
/** UserAction **/
|
|
||||||
final UserState nextState = userReducer(state.userState!, action);
|
final UserState nextState = userReducer(state.userState!, action);
|
||||||
return state.copyWith(userState: nextState);
|
return state.copyWith(userState: nextState);
|
||||||
} else if (action is SetNavStateAction) {
|
} else if (action is SetNavStateAction) {
|
||||||
/** NavAction **/
|
|
||||||
final NavState nextState = navReducer(state.navState!, action);
|
final NavState nextState = navReducer(state.navState!, action);
|
||||||
return state.copyWith(navState: nextState);
|
return state.copyWith(navState: nextState);
|
||||||
} else if (action is SetSellStateAction) {
|
} else if (action is SetSellStateAction) {
|
||||||
/** NavAction **/
|
|
||||||
final SellState nextState = sellReducer(state.sellState!, action);
|
final SellState nextState = sellReducer(state.sellState!, action);
|
||||||
return state.copyWith(sellState: nextState);
|
return state.copyWith(sellState: nextState);
|
||||||
} else if (action is SetJournalStateAction) {
|
} else if (action is SetJournalStateAction) {
|
||||||
/** NavAction **/
|
|
||||||
final JournalState nextState = journalReducer(state.journalState!, action);
|
final JournalState nextState = journalReducer(state.journalState!, action);
|
||||||
return state.copyWith(journalState: nextState);
|
return state.copyWith(journalState: nextState);
|
||||||
|
} else if (action is SetSettingStateAction) {
|
||||||
|
final SettingState nextState = settingReducer(state.settingState!, action);
|
||||||
|
return state.copyWith(settingState: nextState);
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
@ -47,12 +49,14 @@ class AppState {
|
||||||
this.navState,
|
this.navState,
|
||||||
this.sellState,
|
this.sellState,
|
||||||
this.journalState,
|
this.journalState,
|
||||||
|
this.settingState,
|
||||||
});
|
});
|
||||||
|
|
||||||
final UserState? userState;
|
final UserState? userState;
|
||||||
final NavState? navState;
|
final NavState? navState;
|
||||||
final SellState? sellState;
|
final SellState? sellState;
|
||||||
final JournalState? journalState;
|
final JournalState? journalState;
|
||||||
|
final SettingState? settingState;
|
||||||
|
|
||||||
//stable work
|
//stable work
|
||||||
AppState copyWith({
|
AppState copyWith({
|
||||||
|
|
@ -60,12 +64,14 @@ class AppState {
|
||||||
NavState? navState,
|
NavState? navState,
|
||||||
SellState? sellState,
|
SellState? sellState,
|
||||||
JournalState? journalState,
|
JournalState? journalState,
|
||||||
|
SettingState? settingState,
|
||||||
}) {
|
}) {
|
||||||
return AppState(
|
return AppState(
|
||||||
userState: userState ?? this.userState,
|
userState: userState ?? this.userState,
|
||||||
navState: navState ?? this.navState,
|
navState: navState ?? this.navState,
|
||||||
sellState: sellState ?? this.sellState,
|
sellState: sellState ?? this.sellState,
|
||||||
journalState: journalState ?? this.journalState,
|
journalState: journalState ?? this.journalState,
|
||||||
|
settingState: settingState ?? this.settingState,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,6 +79,7 @@ class AppState {
|
||||||
return json != null
|
return json != null
|
||||||
? AppState(
|
? AppState(
|
||||||
userState: UserState.fromJson(json['userState']),
|
userState: UserState.fromJson(json['userState']),
|
||||||
|
settingState: SettingState.fromMap(json['settingState']),
|
||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
@ -80,6 +87,7 @@ class AppState {
|
||||||
dynamic toJson() {
|
dynamic toJson() {
|
||||||
return {
|
return {
|
||||||
'userState': userState!.toJson(),
|
'userState': userState!.toJson(),
|
||||||
|
'settingState': settingState!.toMap(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -112,14 +120,18 @@ class Redux {
|
||||||
final navStateInitial = NavState.initial();
|
final navStateInitial = NavState.initial();
|
||||||
final sellStateInitial = SellState.initial();
|
final sellStateInitial = SellState.initial();
|
||||||
final journalStateInitial = JournalState.initial();
|
final journalStateInitial = JournalState.initial();
|
||||||
|
final settingStateInitial = SettingState.initial(initialState?.settingState);
|
||||||
|
|
||||||
_store = Store<AppState>(appReducer,
|
_store = Store<AppState>(
|
||||||
middleware: [thunkMiddleware, persist.createMiddleware()],
|
appReducer,
|
||||||
initialState: AppState(
|
middleware: [thunkMiddleware, persist.createMiddleware()],
|
||||||
userState: userStateInitial,
|
initialState: AppState(
|
||||||
navState: navStateInitial,
|
userState: userStateInitial,
|
||||||
sellState: sellStateInitial,
|
navState: navStateInitial,
|
||||||
journalState: journalStateInitial,
|
sellState: sellStateInitial,
|
||||||
));
|
journalState: journalStateInitial,
|
||||||
|
settingState: settingStateInitial,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,37 @@
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:charset_converter/charset_converter.dart';
|
import 'package:charset_converter/charset_converter.dart';
|
||||||
|
import 'package:esc_pos_bluetooth/esc_pos_bluetooth.dart';
|
||||||
import 'package:esc_pos_utils/esc_pos_utils.dart';
|
import 'package:esc_pos_utils/esc_pos_utils.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'dart:io';
|
import 'package:flutter_bluetooth_basic/flutter_bluetooth_basic.dart';
|
||||||
import 'package:image/image.dart';
|
import 'package:image/image.dart';
|
||||||
|
import 'package:satu/core/models/settings/printer_setting.dart';
|
||||||
|
|
||||||
|
Future<List<int>> getReceipt(String encoding, String paperSize) async {
|
||||||
|
|
||||||
Future<List<int>> getReceipt() async {
|
|
||||||
final profile = await CapabilityProfile.load();
|
final profile = await CapabilityProfile.load();
|
||||||
final generator = Generator(PaperSize.mm80, profile);
|
final generator = Generator(
|
||||||
List<int> bytes = [];
|
paperSize == PrinterConst.paperSize58mm ? PaperSize.mm58 : PaperSize.mm80,
|
||||||
generator.setGlobalCodeTable('CP866');
|
profile,
|
||||||
Uint8List firstCol = await CharsetConverter.encode('cp866', 'Русский');
|
);
|
||||||
|
|
||||||
bytes += generator.textEncoded(firstCol, styles: const PosStyles(align: PosAlign.left));
|
String codeTable = 'CP866';
|
||||||
|
if(encoding == PrinterConst.encodingCP866) {
|
||||||
|
codeTable = 'CP866';
|
||||||
|
} else if(encoding == PrinterConst.encodingCP1251) {
|
||||||
|
codeTable = 'CP1251';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
List<int> bytes = [];
|
||||||
|
generator.setGlobalCodeTable(codeTable);
|
||||||
|
final Uint8List firstCol =
|
||||||
|
await CharsetConverter.encode(encoding.toLowerCase(), 'Тестовый чек');
|
||||||
|
bytes += generator.textEncoded(firstCol);
|
||||||
|
|
||||||
bytes +=
|
bytes +=
|
||||||
generator.text('Align center', styles: const PosStyles(align: PosAlign.center));
|
generator.text('CENTER', styles: const PosStyles(align: PosAlign.center));
|
||||||
bytes += generator.text('Align right',
|
bytes += generator.text('Right',
|
||||||
styles: const PosStyles(align: PosAlign.right), linesAfter: 1);
|
styles: const PosStyles(align: PosAlign.right), linesAfter: 1);
|
||||||
|
|
||||||
bytes += generator.row([
|
bytes += generator.row([
|
||||||
|
|
@ -40,27 +52,32 @@ Future<List<int>> getReceipt() async {
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// bytes += generator.text('Text size 200%',
|
bytes += generator.text(
|
||||||
// styles: const PosStyles(
|
'Text size 200%',
|
||||||
// height: PosTextSize.size2,
|
styles: const PosStyles(
|
||||||
// width: PosTextSize.size2,
|
height: PosTextSize.size2,
|
||||||
// ));
|
width: PosTextSize.size2,
|
||||||
//
|
),
|
||||||
// // Print barcode
|
);
|
||||||
// final List<int> barData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 4];
|
|
||||||
// bytes += generator.barcode(Barcode.upcA(barData));
|
// Print barcode
|
||||||
|
final List<int> barData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 4];
|
||||||
|
bytes += generator.barcode(Barcode.upcA(barData));
|
||||||
|
|
||||||
bytes += generator.feed(2);
|
bytes += generator.feed(2);
|
||||||
bytes += generator.cut();
|
bytes += generator.cut();
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<int>> getReceiptImg() async {
|
Future<List<int>> getReceiptImg(String paperSize) async {
|
||||||
final profile = await CapabilityProfile.load();
|
final profile = await CapabilityProfile.load();
|
||||||
final generator = Generator(PaperSize.mm80, profile);
|
final generator = Generator(
|
||||||
|
paperSize == PrinterConst.paperSize58mm ? PaperSize.mm58 : PaperSize.mm80,
|
||||||
|
profile,
|
||||||
|
);
|
||||||
List<int> bytes = [];
|
List<int> bytes = [];
|
||||||
generator.setGlobalCodeTable('CP866');
|
final ByteData data =
|
||||||
final ByteData data = await rootBundle.load('assets/images/aman_kassa_check.png') as ByteData;
|
await rootBundle.load('assets/images/aman_kassa_check.png');
|
||||||
final Uint8List imgBytes = data.buffer.asUint8List();
|
final Uint8List imgBytes = data.buffer.asUint8List();
|
||||||
final Image? image = decodeImage(imgBytes);
|
final Image? image = decodeImage(imgBytes);
|
||||||
// Using `ESC *`
|
// Using `ESC *`
|
||||||
|
|
@ -68,4 +85,19 @@ Future<List<int>> getReceiptImg() async {
|
||||||
bytes += generator.feed(2);
|
bytes += generator.feed(2);
|
||||||
bytes += generator.cut();
|
bytes += generator.cut();
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BluetoothDevice printerDeviceToBluetoothDevice(PrinterDevice device) {
|
||||||
|
return BluetoothDevice()
|
||||||
|
..name = device.name
|
||||||
|
..address = device.address
|
||||||
|
..connected = device.connected
|
||||||
|
..type = device.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrinterDevice bluetoothDeviceToPrinterDevice(PrinterBluetooth device) {
|
||||||
|
return PrinterDevice()
|
||||||
|
..name = device.name
|
||||||
|
..address = device.address
|
||||||
|
..type = device.type;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,22 +37,27 @@ class MainApplication extends StatelessWidget {
|
||||||
return StoreProvider<AppState>(
|
return StoreProvider<AppState>(
|
||||||
store: Redux.store!,
|
store: Redux.store!,
|
||||||
child: ScreenUtilInit(
|
child: ScreenUtilInit(
|
||||||
designSize: Size(375, 812),
|
designSize: const Size(
|
||||||
|
375,
|
||||||
|
812,
|
||||||
|
),
|
||||||
builder: () => MaterialApp(
|
builder: () => MaterialApp(
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
primaryColor: whiteColor,
|
primaryColor: whiteColor,
|
||||||
accentColor: primaryColor,
|
scaffoldBackgroundColor: backgroundColor,
|
||||||
scaffoldBackgroundColor: backgroundColor
|
colorScheme:
|
||||||
// textTheme: GoogleFonts.robotoTextTheme(
|
ColorScheme.fromSwatch().copyWith(secondary: primaryColor),
|
||||||
// Theme.of(context).textTheme,
|
// textTheme: GoogleFonts.robotoTextTheme(
|
||||||
// )
|
// Theme.of(context).textTheme,
|
||||||
),
|
// )
|
||||||
|
),
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
builder: (context, child) => Navigator(
|
builder: (context, child) => Navigator(
|
||||||
key: locator<DialogService>().dialogNavigationKey,
|
key: locator<DialogService>().dialogNavigationKey,
|
||||||
onGenerateRoute: (settings) => MaterialPageRoute(
|
onGenerateRoute: (settings) => MaterialPageRoute(
|
||||||
builder: (context) => DialogManager(child: child!)),
|
builder: (context) => DialogManager(child: child!),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
navigatorKey: locator<NavigatorService>().navigatorKey,
|
navigatorKey: locator<NavigatorService>().navigatorKey,
|
||||||
home: StartUpView(),
|
home: StartUpView(),
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,29 @@
|
||||||
|
// login
|
||||||
const String loginViewRoute = 'LoginView';
|
const String loginViewRoute = 'LoginView';
|
||||||
|
// main
|
||||||
const String mainViewRoute = 'MainView';
|
const String mainViewRoute = 'MainView';
|
||||||
|
|
||||||
|
// work - tabs page
|
||||||
const String workViewRoute = 'WorkView';
|
const String workViewRoute = 'WorkView';
|
||||||
const String addProductViewRoute = 'AddProductView';
|
const String addProductViewRoute = 'AddProductView';
|
||||||
const String addByBarcodeViewRoute = 'AddByBarcodeView';
|
const String addByBarcodeViewRoute = 'AddByBarcodeView';
|
||||||
|
|
||||||
const String contragentSelectViewRoute = 'ContragentSelectViewRoute';
|
|
||||||
|
|
||||||
const String paymentViewRoute = 'paymentViewRoute';
|
const String paymentViewRoute = 'paymentViewRoute';
|
||||||
const String receiptViewRoute = 'receiptViewRoute';
|
const String receiptViewRoute = 'receiptViewRoute';
|
||||||
|
|
||||||
const String settingPrinterBluetoothViewRoute = 'SettingPrinterBluetoothView';
|
|
||||||
|
|
||||||
|
|
||||||
// Generate the views here
|
|
||||||
|
|
||||||
|
|
||||||
|
// dictionaries - category
|
||||||
const String categoryEditRoute = 'categoryEditRoute';
|
const String categoryEditRoute = 'categoryEditRoute';
|
||||||
const String categorySelectViewRoute = 'categorySelectViewRoute';
|
const String categorySelectViewRoute = 'categorySelectViewRoute';
|
||||||
|
// dictionaries - good
|
||||||
const String goodsEditRoute = 'goodsEditRoute';
|
const String goodsEditRoute = 'goodsEditRoute';
|
||||||
const String goodsDictionaryViewRoute = 'goodsDictionaryViewRoute';
|
const String goodsDictionaryViewRoute = 'goodsDictionaryViewRoute';
|
||||||
|
//dictionaries - contragent
|
||||||
|
const String contragentSelectViewRoute = 'ContragentSelectViewRoute';
|
||||||
|
|
||||||
|
|
||||||
|
// setting - ble printer
|
||||||
|
const String settingPrinterBluetoothViewRoute = 'SettingPrinterBluetoothView';
|
||||||
|
const String settingPrinterBluetoothSelectViewRoute = 'settingPrinterBluetoothSelectViewRoute';
|
||||||
|
const String settingPrinterPaperSizeViewRoute = 'settingPrinterPaperSizeViewRoute';
|
||||||
|
const String settingPrinterEncodingViewRoute = 'settingPrinterEncodingViewRoute';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:satu/core/models/dictionary/category_row_data.dart';
|
import 'package:satu/core/models/dictionary/category_row_data.dart';
|
||||||
import 'package:satu/core/models/dictionary/good_row_data.dart';
|
import 'package:satu/core/models/dictionary/good_row_data.dart';
|
||||||
|
|
@ -8,6 +7,9 @@ import 'package:satu/views/dictionaries/category/category_select_view.dart';
|
||||||
import 'package:satu/views/dictionaries/goods/goods_edit.dart';
|
import 'package:satu/views/dictionaries/goods/goods_edit.dart';
|
||||||
import 'package:satu/views/login/login_view.dart';
|
import 'package:satu/views/login/login_view.dart';
|
||||||
import 'package:satu/views/main/main_view.dart';
|
import 'package:satu/views/main/main_view.dart';
|
||||||
|
import 'package:satu/views/settings/printer_bluetooth/printer_encoding_select.dart';
|
||||||
|
import 'package:satu/views/settings/printer_bluetooth/printer_paper_size_select.dart';
|
||||||
|
import 'package:satu/views/settings/printer_bluetooth/printer_select.dart';
|
||||||
import 'package:satu/views/settings/printer_bluetooth/printer_view.dart';
|
import 'package:satu/views/settings/printer_bluetooth/printer_view.dart';
|
||||||
import 'package:satu/views/work/views/add_by_barcode/add_by_barcode_view.dart';
|
import 'package:satu/views/work/views/add_by_barcode/add_by_barcode_view.dart';
|
||||||
import 'package:satu/views/work/views/add_product/add_product_view.dart';
|
import 'package:satu/views/work/views/add_product/add_product_view.dart';
|
||||||
|
|
@ -23,60 +25,79 @@ Route<dynamic> generateRoute(RouteSettings settings) {
|
||||||
case loginViewRoute:
|
case loginViewRoute:
|
||||||
//LoginModel model = settings.arguments as LoginModel;
|
//LoginModel model = settings.arguments as LoginModel;
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name!,
|
routeName: settings.name,
|
||||||
viewToShow: LoginView(),
|
viewToShow: LoginView(),
|
||||||
);
|
);
|
||||||
case workViewRoute:
|
case workViewRoute:
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name!,
|
routeName: settings.name,
|
||||||
viewToShow: WorkView(),
|
viewToShow: const WorkView(),
|
||||||
);
|
);
|
||||||
case mainViewRoute:
|
case mainViewRoute:
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name!,
|
routeName: settings.name,
|
||||||
viewToShow: MainView(),
|
viewToShow: MainView(),
|
||||||
);
|
);
|
||||||
case addProductViewRoute:
|
case addProductViewRoute:
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name!,
|
routeName: settings.name,
|
||||||
viewToShow: AddProductView(),
|
viewToShow: AddProductView(),
|
||||||
);
|
);
|
||||||
case addByBarcodeViewRoute:
|
case addByBarcodeViewRoute:
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name!,
|
routeName: settings.name,
|
||||||
viewToShow: AddByBarcodeView(),
|
viewToShow: const AddByBarcodeView(),
|
||||||
);
|
);
|
||||||
case settingPrinterBluetoothViewRoute:
|
case settingPrinterBluetoothViewRoute:
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name!,
|
routeName: settings.name,
|
||||||
viewToShow: const PrinterView(),
|
viewToShow: const PrinterView(),
|
||||||
);
|
);
|
||||||
|
case settingPrinterBluetoothSelectViewRoute:
|
||||||
|
return _getPageRoute(
|
||||||
|
routeName: settings.name,
|
||||||
|
viewToShow: const PrinterSelect(),
|
||||||
|
);
|
||||||
|
case settingPrinterPaperSizeViewRoute:
|
||||||
|
return _getPageRoute(
|
||||||
|
routeName: settings.name,
|
||||||
|
viewToShow: const PrinterPaperSizeView(),
|
||||||
|
);
|
||||||
|
case settingPrinterEncodingViewRoute:
|
||||||
|
return _getPageRoute(
|
||||||
|
routeName: settings.name,
|
||||||
|
viewToShow: const PrinterEncodingView(),
|
||||||
|
);
|
||||||
case contragentSelectViewRoute:
|
case contragentSelectViewRoute:
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name!,
|
routeName: settings.name,
|
||||||
viewToShow: SelectContragentView(),
|
viewToShow: SelectContragentView(),
|
||||||
);
|
);
|
||||||
case paymentViewRoute:
|
case paymentViewRoute:
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name!,
|
routeName: settings.name,
|
||||||
viewToShow: const PaymentView(),
|
viewToShow: const PaymentView(),
|
||||||
);
|
);
|
||||||
case categoryEditRoute:
|
case categoryEditRoute:
|
||||||
final CategoryRowDao category = settings.arguments! as CategoryRowDao;
|
final CategoryRowDao category = settings.arguments! as CategoryRowDao;
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name!,
|
routeName: settings.name,
|
||||||
viewToShow: CategoryEdit(category: category,),
|
viewToShow: CategoryEdit(
|
||||||
|
category: category,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
case categorySelectViewRoute:
|
case categorySelectViewRoute:
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name!,
|
routeName: settings.name,
|
||||||
viewToShow: CategorySelectView(),
|
viewToShow: CategorySelectView(),
|
||||||
);
|
);
|
||||||
case goodsEditRoute:
|
case goodsEditRoute:
|
||||||
final GoodRowDao good = settings.arguments! as GoodRowDao;
|
final GoodRowDao good = settings.arguments! as GoodRowDao;
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name!,
|
routeName: settings.name,
|
||||||
viewToShow: GoodEdit(good: good,),
|
viewToShow: GoodEdit(
|
||||||
|
good: good,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
case receiptViewRoute:
|
case receiptViewRoute:
|
||||||
|
|
@ -84,7 +105,9 @@ Route<dynamic> generateRoute(RouteSettings settings) {
|
||||||
//return SlideRightRoute(widget: ImageShowContainer(data));
|
//return SlideRightRoute(widget: ImageShowContainer(data));
|
||||||
return _getPageRoute(
|
return _getPageRoute(
|
||||||
routeName: settings.name,
|
routeName: settings.name,
|
||||||
viewToShow: ReceiptView(transactionData: data,),
|
viewToShow: ReceiptView(
|
||||||
|
transactionData: data,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return MaterialPageRoute(
|
return MaterialPageRoute(
|
||||||
|
|
@ -104,7 +127,6 @@ PageRoute _getPageRoute({String? routeName, Widget? viewToShow}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class SlideRightRoute extends PageRouteBuilder {
|
class SlideRightRoute extends PageRouteBuilder {
|
||||||
final Widget? widget;
|
|
||||||
SlideRightRoute({this.widget})
|
SlideRightRoute({this.widget})
|
||||||
: super(
|
: super(
|
||||||
pageBuilder: (BuildContext context, Animation<double> animation,
|
pageBuilder: (BuildContext context, Animation<double> animation,
|
||||||
|
|
@ -115,8 +137,8 @@ class SlideRightRoute extends PageRouteBuilder {
|
||||||
Animation<double> animation,
|
Animation<double> animation,
|
||||||
Animation<double> secondaryAnimation,
|
Animation<double> secondaryAnimation,
|
||||||
Widget child) {
|
Widget child) {
|
||||||
return new SlideTransition(
|
return SlideTransition(
|
||||||
position: new Tween<Offset>(
|
position: Tween<Offset>(
|
||||||
begin: const Offset(1.0, 0.0),
|
begin: const Offset(1.0, 0.0),
|
||||||
end: Offset.zero,
|
end: Offset.zero,
|
||||||
).animate(animation),
|
).animate(animation),
|
||||||
|
|
@ -124,4 +146,5 @@ class SlideRightRoute extends PageRouteBuilder {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
final Widget? widget;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
|
import 'package:satu/core/models/settings/printer_setting.dart';
|
||||||
|
import 'package:satu/core/redux/actions/setting_actions.dart';
|
||||||
|
import 'package:satu/core/redux/store.dart';
|
||||||
|
import 'package:satu/widgets/bar/products_app_bar.dart';
|
||||||
|
import 'package:satu/widgets/bar/products_title_bar.dart';
|
||||||
|
import 'package:satu/widgets/fields/line_checkbox.dart';
|
||||||
|
|
||||||
|
class PrinterEncodingView extends StatelessWidget {
|
||||||
|
const PrinterEncodingView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: const ProductsAppBar(
|
||||||
|
title: 'Кодировка печати',
|
||||||
|
),
|
||||||
|
body: StoreConnector<AppState,PrinterSetting>(
|
||||||
|
converter: (store) => store.state.settingState!.printer!,
|
||||||
|
builder: (context, printer) {
|
||||||
|
return Column(children: [
|
||||||
|
const ProductsTitleBarBar(title: 'Выберите кодировку принтера'),
|
||||||
|
LineCheckBox(
|
||||||
|
PrinterConst.encodingCP866,
|
||||||
|
value: printer.encoding == PrinterConst.encodingCP866,
|
||||||
|
onTap: () => {
|
||||||
|
Redux.store!.dispatch(
|
||||||
|
setEncodingPrint(PrinterConst.encodingCP866),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const Divider(height: 1,),
|
||||||
|
LineCheckBox(
|
||||||
|
PrinterConst.encodingCP1251,
|
||||||
|
value: printer.encoding == PrinterConst.encodingCP1251,
|
||||||
|
onTap: () => {
|
||||||
|
Redux.store!.dispatch(
|
||||||
|
setEncodingPrint(PrinterConst.encodingCP1251),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const Divider(height: 1,),
|
||||||
|
LineCheckBox(
|
||||||
|
PrinterConst.encodingBigEncoding,
|
||||||
|
value: printer.encoding == PrinterConst.encodingBigEncoding,
|
||||||
|
onTap: () => {
|
||||||
|
Redux.store!.dispatch(
|
||||||
|
setEncodingPrint(PrinterConst.encodingBigEncoding),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
|
import 'package:satu/core/models/settings/printer_setting.dart';
|
||||||
|
import 'package:satu/core/redux/actions/setting_actions.dart';
|
||||||
|
import 'package:satu/core/redux/store.dart';
|
||||||
|
import 'package:satu/widgets/bar/products_app_bar.dart';
|
||||||
|
import 'package:satu/widgets/bar/products_title_bar.dart';
|
||||||
|
import 'package:satu/widgets/fields/line_checkbox.dart';
|
||||||
|
|
||||||
|
class PrinterPaperSizeView extends StatelessWidget {
|
||||||
|
const PrinterPaperSizeView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: const ProductsAppBar(
|
||||||
|
title: 'Размер чека',
|
||||||
|
),
|
||||||
|
body: StoreConnector<AppState,PrinterSetting>(
|
||||||
|
converter: (store) => store.state.settingState!.printer!,
|
||||||
|
builder: (context, printer) {
|
||||||
|
return Column(children: [
|
||||||
|
const ProductsTitleBarBar(title: 'Выберите размер чека'),
|
||||||
|
LineCheckBox(
|
||||||
|
PrinterConst.paperSize58mm,
|
||||||
|
value: printer.paperSize == PrinterConst.paperSize58mm,
|
||||||
|
onTap: () => {
|
||||||
|
Redux.store!.dispatch(
|
||||||
|
setPaperSize(PrinterConst.paperSize58mm),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const Divider(height: 1,),
|
||||||
|
LineCheckBox(
|
||||||
|
PrinterConst.paperSize80mm,
|
||||||
|
value: printer.paperSize == PrinterConst.paperSize80mm,
|
||||||
|
onTap: () => {
|
||||||
|
Redux.store!.dispatch(
|
||||||
|
setPaperSize(PrinterConst.paperSize80mm),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,15 +2,21 @@ import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:bluetooth_print/bluetooth_print.dart';
|
// import 'package:bluetooth_print/bluetooth_print.dart';
|
||||||
import 'package:bluetooth_print/bluetooth_print_model.dart';
|
// import 'package:bluetooth_print/bluetooth_print_model.dart';
|
||||||
import 'package:charset_converter/charset_converter.dart';
|
import 'package:esc_pos_bluetooth/esc_pos_bluetooth.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
|
|
||||||
import 'package:logger/logger.dart';
|
import 'package:logger/logger.dart';
|
||||||
|
import 'package:satu/core/models/settings/printer_setting.dart';
|
||||||
|
import 'package:satu/core/redux/actions/setting_actions.dart';
|
||||||
|
import 'package:satu/core/redux/store.dart';
|
||||||
import 'package:satu/core/utils/logger.dart';
|
import 'package:satu/core/utils/logger.dart';
|
||||||
import 'package:satu/core/utils/pos_printer.dart';
|
import 'package:satu/core/utils/pos_printer.dart';
|
||||||
|
import 'package:satu/widgets/bar/products_app_bar.dart';
|
||||||
|
import 'package:satu/widgets/bar/products_title_bar.dart';
|
||||||
|
import 'package:satu/widgets/fields/line_checkbox.dart';
|
||||||
|
|
||||||
class PrinterSelect extends StatefulWidget {
|
class PrinterSelect extends StatefulWidget {
|
||||||
const PrinterSelect({Key? key}) : super(key: key);
|
const PrinterSelect({Key? key}) : super(key: key);
|
||||||
|
|
@ -21,186 +27,125 @@ class PrinterSelect extends StatefulWidget {
|
||||||
|
|
||||||
class _PrinterSelectState extends State<PrinterSelect> {
|
class _PrinterSelectState extends State<PrinterSelect> {
|
||||||
final Logger log = getLogger('_PrinterViewState');
|
final Logger log = getLogger('_PrinterViewState');
|
||||||
BluetoothPrint? bluetoothPrint;
|
|
||||||
|
|
||||||
bool _connected = false;
|
//BluetoothPrint? bluetoothPrint;
|
||||||
BluetoothDevice? _device;
|
//
|
||||||
String tips = 'no device connect';
|
// bool _connected = false;
|
||||||
|
// BluetoothDevice? _device;
|
||||||
|
PrinterBluetoothManager printerManager = PrinterBluetoothManager();
|
||||||
|
List<PrinterBluetooth> _devices = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
bluetoothPrint = BluetoothPrint.instance;
|
//bluetoothPrint = BluetoothPrint.instance;
|
||||||
if (WidgetsBinding.instance != null) {
|
// if (WidgetsBinding.instance != null) {
|
||||||
WidgetsBinding.instance!.addPostFrameCallback((_) => initBluetooth());
|
// WidgetsBinding.instance!.addPostFrameCallback((_) => initBluetooth());
|
||||||
}
|
// }
|
||||||
|
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
|
printerManager.scanResults.listen((devices) async {
|
||||||
|
// print('UI: Devices found ${devices.length}');
|
||||||
|
setState(() {
|
||||||
|
_devices = devices;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
_startScanDevices();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _startScanDevices() {
|
||||||
|
setState(() {
|
||||||
|
_devices = [];
|
||||||
|
});
|
||||||
|
printerManager.startScan(Duration(seconds: 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _stopScanDevices() {
|
||||||
|
printerManager.stopScan();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Platform messages are asynchronous, so we initialize in an async method.
|
// Platform messages are asynchronous, so we initialize in an async method.
|
||||||
Future<void> initBluetooth() async {
|
// Future<void> initBluetooth() async {
|
||||||
bluetoothPrint!.startScan(timeout: Duration(seconds: 4));
|
// bluetoothPrint!.startScan(timeout: const Duration(seconds: 4));
|
||||||
|
//
|
||||||
final bool isConnected = await bluetoothPrint!.isConnected ?? false;
|
// //final bool isConnected = await bluetoothPrint!.isConnected ?? false;
|
||||||
|
//
|
||||||
bluetoothPrint!.state.listen((state) {
|
// // bluetoothPrint!.state.listen((state) {
|
||||||
print('cur device status: $state');
|
// // print('cur device status: $state');
|
||||||
|
// //
|
||||||
switch (state) {
|
// // switch (state) {
|
||||||
case BluetoothPrint.CONNECTED:
|
// // case BluetoothPrint.CONNECTED:
|
||||||
setState(() {
|
// // setState(() {
|
||||||
_connected = true;
|
// // _connected = true;
|
||||||
tips = 'connect success';
|
// // tips = 'connect success';
|
||||||
});
|
// // });
|
||||||
break;
|
// // break;
|
||||||
case BluetoothPrint.DISCONNECTED:
|
// // case BluetoothPrint.DISCONNECTED:
|
||||||
setState(() {
|
// // setState(() {
|
||||||
_connected = false;
|
// // _connected = false;
|
||||||
tips = 'disconnect success';
|
// // tips = 'disconnect success';
|
||||||
});
|
// // });
|
||||||
break;
|
// // break;
|
||||||
default:
|
// // default:
|
||||||
break;
|
// // break;
|
||||||
}
|
// // }
|
||||||
});
|
// // });
|
||||||
|
//
|
||||||
if (!mounted) return;
|
// if (!mounted) return;
|
||||||
|
//
|
||||||
if (isConnected) {
|
// // if (isConnected) {
|
||||||
setState(() {
|
// // setState(() {
|
||||||
_connected = true;
|
// // _connected = true;
|
||||||
});
|
// // });
|
||||||
}
|
// // }
|
||||||
}
|
// }
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return Scaffold(
|
||||||
home: Scaffold(
|
appBar: const ProductsAppBar(
|
||||||
appBar: AppBar(
|
title: 'Поиск устройства печати',
|
||||||
title: const Text('BluetoothPrint example app'),
|
),
|
||||||
),
|
body: SingleChildScrollView(
|
||||||
body: RefreshIndicator(
|
child: StoreConnector<AppState, PrinterSetting>(
|
||||||
onRefresh: () =>
|
converter: (store) => store.state.settingState!.printer!,
|
||||||
bluetoothPrint!.startScan(timeout: Duration(seconds: 4)),
|
builder: (context, printer) {
|
||||||
child: SingleChildScrollView(
|
return Column(
|
||||||
child: Column(
|
children: <Widget>[
|
||||||
children: <Widget>[
|
const ProductsTitleBarBar(
|
||||||
Row(
|
title: 'Выберите устройство печати'),
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
StreamBuilder<List<PrinterBluetooth>>(
|
||||||
children: <Widget>[
|
stream: printerManager.scanResults,
|
||||||
Padding(
|
initialData: const [],
|
||||||
padding:
|
builder: (c, snapshot) => Column(
|
||||||
EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
children: (snapshot.data ?? [])
|
||||||
child: Text(tips),
|
.map(
|
||||||
),
|
(d) => Column(
|
||||||
],
|
children: [
|
||||||
),
|
LineCheckBox(
|
||||||
const Divider(),
|
d.name ?? '',
|
||||||
StreamBuilder<List<BluetoothDevice>>(
|
value: printer.device != null &&
|
||||||
stream: bluetoothPrint!.scanResults,
|
printer.device!.address == d.address,
|
||||||
initialData: const [],
|
onTap: () => {
|
||||||
builder: (c, snapshot) => Column(
|
Redux.store!.dispatch(
|
||||||
children: (snapshot.data ?? [])
|
selectBluetoothDevice(
|
||||||
.map((d) => ListTile(
|
bluetoothDeviceToPrinterDevice(d),
|
||||||
title: Text(d.name ?? ''),
|
),
|
||||||
subtitle: Text(d.address ?? ''),
|
|
||||||
onTap: () async {
|
|
||||||
setState(() {
|
|
||||||
_device = d;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
trailing: _device != null &&
|
|
||||||
_device!.address == d.address
|
|
||||||
? const Icon(
|
|
||||||
Icons.check,
|
|
||||||
color: Colors.green,
|
|
||||||
)
|
)
|
||||||
: null,
|
|
||||||
))
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Divider(),
|
|
||||||
Container(
|
|
||||||
padding: EdgeInsets.fromLTRB(20, 5, 20, 10),
|
|
||||||
child: Column(
|
|
||||||
children: <Widget>[
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: <Widget>[
|
|
||||||
OutlinedButton(
|
|
||||||
onPressed: _connected
|
|
||||||
? null
|
|
||||||
: () async {
|
|
||||||
if (_device != null &&
|
|
||||||
_device!.address != null) {
|
|
||||||
await bluetoothPrint!.connect(_device!);
|
|
||||||
} else {
|
|
||||||
setState(() {
|
|
||||||
tips = 'please select device';
|
|
||||||
});
|
|
||||||
print('please select device');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
child: const Text('connect'),
|
),
|
||||||
),
|
const Divider(
|
||||||
SizedBox(width: 10.0),
|
height: 1,
|
||||||
OutlinedButton(
|
),
|
||||||
onPressed: _connected
|
],
|
||||||
? () async {
|
),
|
||||||
await bluetoothPrint!.disconnect();
|
)
|
||||||
}
|
.toList(),
|
||||||
: null,
|
),
|
||||||
child: const Text('disconnect'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
OutlinedButton(
|
|
||||||
onPressed: _connected
|
|
||||||
? () async {
|
|
||||||
Map<String, dynamic> config = Map();
|
|
||||||
await bluetoothPrint!
|
|
||||||
.rawBytes(config, await getReceipt());
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
child: const Text('print receipt(esc) - text'),
|
|
||||||
),
|
|
||||||
OutlinedButton(
|
|
||||||
onPressed: _connected
|
|
||||||
? () async {
|
|
||||||
Map<String, dynamic> config = Map();
|
|
||||||
await bluetoothPrint!
|
|
||||||
.rawBytes(config, await getReceiptImg());
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
child: const Text('print label(esc) img'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
)
|
],
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
floatingActionButton: StreamBuilder<bool>(
|
|
||||||
stream: bluetoothPrint!.isScanning,
|
|
||||||
initialData: false,
|
|
||||||
builder: (c, snapshot) {
|
|
||||||
if (snapshot.data != null) {
|
|
||||||
return FloatingActionButton(
|
|
||||||
onPressed: () => bluetoothPrint!.stopScan(),
|
|
||||||
backgroundColor: Colors.red,
|
|
||||||
child: const Icon(Icons.stop),
|
|
||||||
);
|
);
|
||||||
} else {
|
}),
|
||||||
return FloatingActionButton(
|
|
||||||
child: const Icon(Icons.search),
|
|
||||||
onPressed: () => bluetoothPrint!
|
|
||||||
.startScan(timeout: const Duration(seconds: 4)));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,18 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:esc_pos_bluetooth/esc_pos_bluetooth.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
|
import 'package:satu/core/models/settings/printer_setting.dart';
|
||||||
|
import 'package:satu/core/redux/store.dart';
|
||||||
|
import 'package:satu/core/services/dialog_service.dart';
|
||||||
|
import 'package:satu/core/services/navigator_service.dart';
|
||||||
|
import 'package:satu/core/utils/locator.dart';
|
||||||
|
import 'package:satu/core/utils/pos_printer.dart';
|
||||||
|
import 'package:satu/routes/route_names.dart';
|
||||||
import 'package:satu/shared/app_colors.dart';
|
import 'package:satu/shared/app_colors.dart';
|
||||||
import 'package:satu/shared/ui_helpers.dart';
|
import 'package:satu/shared/ui_helpers.dart';
|
||||||
import 'package:satu/widgets/bar/products_app_bar.dart';
|
import 'package:satu/widgets/bar/products_app_bar.dart';
|
||||||
import 'package:satu/widgets/bar/products_title_bar.dart';
|
|
||||||
import 'package:satu/widgets/fields/line_tile.dart';
|
import 'package:satu/widgets/fields/line_tile.dart';
|
||||||
|
|
||||||
class PrinterView extends StatefulWidget {
|
class PrinterView extends StatefulWidget {
|
||||||
|
|
@ -13,49 +23,127 @@ class PrinterView extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PrinterViewState extends State<PrinterView> {
|
class _PrinterViewState extends State<PrinterView> {
|
||||||
|
final NavigatorService _navigatorService = locator<NavigatorService>();
|
||||||
|
final DialogService _dialogService = locator<DialogService>();
|
||||||
|
PrinterBluetoothManager printerManager = PrinterBluetoothManager();
|
||||||
|
|
||||||
|
bool printerLocked = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printTest() async {
|
||||||
|
setState(() {
|
||||||
|
printerLocked = true;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
PrinterSetting printerSetting = Redux.store!.state.settingState!.printer!;
|
||||||
|
printerManager.selectPrinter(
|
||||||
|
PrinterBluetooth(
|
||||||
|
printerDeviceToBluetoothDevice(printerSetting.device!),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
bool isIos = Platform.isIOS;
|
||||||
|
int chunkSizeBytes = 3096;
|
||||||
|
int queueSleepTimeMs = 100;
|
||||||
|
|
||||||
|
if (isIos) {
|
||||||
|
chunkSizeBytes = 75;
|
||||||
|
queueSleepTimeMs = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(PrinterConst.encodingBigEncoding == printerSetting.encoding ) {
|
||||||
|
PosPrintResult printResult = await printerManager.writeBytes(
|
||||||
|
await getReceiptImg(
|
||||||
|
printerSetting.paperSize!,
|
||||||
|
),
|
||||||
|
chunkSizeBytes: chunkSizeBytes,
|
||||||
|
queueSleepTimeMs: queueSleepTimeMs,
|
||||||
|
);
|
||||||
|
if(printResult.value != 1) {
|
||||||
|
_dialogService.showDialog(description: printResult.msg);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
PosPrintResult printResult = await printerManager.writeBytes(
|
||||||
|
await getReceipt(
|
||||||
|
printerSetting.encoding!,
|
||||||
|
printerSetting.paperSize!,
|
||||||
|
),
|
||||||
|
chunkSizeBytes: chunkSizeBytes,
|
||||||
|
queueSleepTimeMs: queueSleepTimeMs,
|
||||||
|
);
|
||||||
|
if(printResult.value != 1) {
|
||||||
|
_dialogService.showDialog(description: printResult.msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
await Future.delayed(const Duration(seconds: 7));
|
||||||
|
setState(() {
|
||||||
|
printerLocked = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: ProductsAppBar(
|
appBar: ProductsAppBar(
|
||||||
title: 'Принтер',
|
title: 'Принтер',
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
StoreConnector<AppState, PrinterSetting>(
|
||||||
onPressed: () {},
|
converter: (store) => store.state.settingState!.printer!,
|
||||||
icon: const Icon(
|
builder: (context, snapshot) {
|
||||||
Icons.print,
|
final bool success =
|
||||||
color: placeholderColor,
|
snapshot.device != null && printerLocked == false;
|
||||||
),
|
return IconButton(
|
||||||
|
onPressed: success ? printTest : null,
|
||||||
|
icon: Icon(
|
||||||
|
Icons.print,
|
||||||
|
color: success ? textColor : placeholderColor,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
child: Column(
|
child: StoreConnector<AppState, PrinterSetting>(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
converter: (store) => store.state.settingState!.printer!,
|
||||||
children: [
|
builder: (context, printer) {
|
||||||
verticalSpaceSmall,
|
return Column(
|
||||||
LineTile(
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
'Устройство не выбрано',
|
children: [
|
||||||
onTap: () {},
|
verticalSpaceSmall,
|
||||||
labelText: 'Устройство печати',
|
LineTile(
|
||||||
),
|
printer.device?.name ?? 'Устройство не выбрано',
|
||||||
verticalSpaceSmall,
|
onTap: () {
|
||||||
LineTile(
|
_navigatorService
|
||||||
'Размер не указан',
|
.push(settingPrinterBluetoothSelectViewRoute);
|
||||||
onTap: () {},
|
},
|
||||||
labelText: 'Размер чека',
|
labelText: 'Устройство печати',
|
||||||
),
|
),
|
||||||
verticalSpaceSmall,
|
verticalSpaceSmall,
|
||||||
LineTile(
|
LineTile(
|
||||||
'Кодировка не указана',
|
printer.paperSize ?? 'Размер не указан',
|
||||||
onTap: () {},
|
onTap: () {
|
||||||
labelText: 'Кодировка печати',
|
_navigatorService.push(settingPrinterPaperSizeViewRoute);
|
||||||
),
|
},
|
||||||
],
|
labelText: 'Размер чека',
|
||||||
|
),
|
||||||
|
verticalSpaceSmall,
|
||||||
|
LineTile(
|
||||||
|
printer.encoding ?? 'Кодировка не указана',
|
||||||
|
onTap: () {
|
||||||
|
_navigatorService.push(settingPrinterEncodingViewRoute);
|
||||||
|
},
|
||||||
|
labelText: 'Кодировка печати',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
57
pubspec.lock
57
pubspec.lock
|
|
@ -43,13 +43,6 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.0-nullsafety.0"
|
version: "3.0.0-nullsafety.0"
|
||||||
bluetooth_print:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
path: "../bluetooth_print"
|
|
||||||
relative: true
|
|
||||||
source: path
|
|
||||||
version: "3.0.1"
|
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -134,6 +127,13 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.3"
|
version: "2.0.3"
|
||||||
|
esc_pos_bluetooth:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: esc_pos_bluetooth
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.4.1"
|
||||||
esc_pos_utils:
|
esc_pos_utils:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
@ -162,25 +162,18 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "6.1.2"
|
version: "6.1.2"
|
||||||
fixnum:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: fixnum
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.0"
|
|
||||||
flutter:
|
flutter:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
flutter_reactive_ble:
|
flutter_bluetooth_basic:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: flutter_reactive_ble
|
name: flutter_bluetooth_basic
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.1"
|
version: "0.1.7"
|
||||||
flutter_redux:
|
flutter_redux:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
@ -212,13 +205,6 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
functional_data:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: functional_data
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "1.0.0"
|
|
||||||
gbk_codec:
|
gbk_codec:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -471,13 +457,6 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.2.3"
|
version: "4.2.3"
|
||||||
protobuf:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: protobuf
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "2.0.0"
|
|
||||||
provider:
|
provider:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
@ -499,20 +478,6 @@ packages:
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.0"
|
version: "4.0.0"
|
||||||
reactive_ble_mobile:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: reactive_ble_mobile
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "4.0.1"
|
|
||||||
reactive_ble_platform_interface:
|
|
||||||
dependency: transitive
|
|
||||||
description:
|
|
||||||
name: reactive_ble_platform_interface
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "4.0.1"
|
|
||||||
redux:
|
redux:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
@ -554,7 +519,7 @@ packages:
|
||||||
name: rxdart
|
name: rxdart
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.27.2"
|
version: "0.26.0"
|
||||||
shared_preferences:
|
shared_preferences:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
11
pubspec.yaml
11
pubspec.yaml
|
|
@ -23,10 +23,6 @@ environment:
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
|
||||||
# Use with the CupertinoIcons class for iOS style icons.
|
|
||||||
cupertino_icons: ^1.0.3
|
cupertino_icons: ^1.0.3
|
||||||
redux: ^5.0.0
|
redux: ^5.0.0
|
||||||
flutter_redux: ^0.8.2
|
flutter_redux: ^0.8.2
|
||||||
|
|
@ -58,13 +54,10 @@ dependencies:
|
||||||
permission_handler: ^8.1.6
|
permission_handler: ^8.1.6
|
||||||
flutter_svg: ^0.22.0
|
flutter_svg: ^0.22.0
|
||||||
grouped_list: ^4.1.0
|
grouped_list: ^4.1.0
|
||||||
#flutter_reactive_ble
|
flutter_bluetooth_basic: ^0.1.7
|
||||||
flutter_reactive_ble: ^4.0.1
|
|
||||||
location_permissions: ^4.0.0
|
location_permissions: ^4.0.0
|
||||||
bluetooth_print:
|
|
||||||
path: ../bluetooth_print/
|
|
||||||
esc_pos_utils: ^1.1.0
|
esc_pos_utils: ^1.1.0
|
||||||
# flutter_blue: ^0.8.0
|
esc_pos_bluetooth: ^0.4.1
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue