Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
blackangiliq authored Apr 26, 2022
0 parents commit b25a86f
Show file tree
Hide file tree
Showing 4 changed files with 374 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ImagestorByte.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'dart:typed_data';

late Uint8List theimageThatComesfromThePrinter ;
261 changes: 261 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:printer_test_youtube/ImagestorByte.dart';
import 'package:printer_test_youtube/printer.dart';
import 'package:screenshot/screenshot.dart';
import 'package:esc_pos_printer/esc_pos_printer.dart';
import 'package:esc_pos_utils/esc_pos_utils.dart';
import 'dart:io';

void main() {
runApp(const MyApp());
}

class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);

@override
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
ScreenshotController screenshotController = ScreenshotController();
String dir = Directory.current.path;
@override
void initState() {
// TODO: implement initState
super.initState();
// print(dir);
// setState(() {
// Process.run('$dir/images/installerX64/install.exe', [' start '])
// .then((ProcessResult results) {
// print(results.stdout);
// });
// });
}
void testPrint(String printerIp, Uint8List theimageThatComesfr) async {
print("im inside the test print 2");
// TODO Don't forget to choose printer's paper size
const PaperSize paper = PaperSize.mm80;
final profile = await CapabilityProfile.load();
final printer = NetworkPrinter(paper, profile);

final PosPrintResult res = await printer.connect(printerIp, port: 9100);

if (res == PosPrintResult.success) {
// DEMO RECEIPT
await testReceipt(printer, theimageThatComesfr);
print(res.msg);
await Future.delayed(const Duration(seconds: 3), () {
print("prinnter desconect");
printer.disconnect();
});
}
}
TextEditingController Printer = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("معاينة الوصل قبل الطباعة "),
),
body: Center(
child: ListView(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
TextField(
controller: Printer,
decoration: const InputDecoration(hintText: "printer ip"),
),

const SizedBox(
height: 10,
),
ElevatedButton(
child: const Text(
'print res',
style: TextStyle(fontSize: 40),
),
onPressed: () {
screenshotController
.capture(delay: const Duration(milliseconds: 10))
.then((capturedImage) async {
theimageThatComesfromThePrinter = capturedImage!;
setState(() {
theimageThatComesfromThePrinter = capturedImage;
testPrint(Printer.text, theimageThatComesfromThePrinter);
});
}).catchError((onError) {
print(onError);
});
},
),
const SizedBox(
height: 10,
),
Screenshot(
controller: screenshotController,
child: Container(
width: 140,
child: Column(
children: [
Row(
children: const [
Text(
"محمد نعم 臺灣 ",
style: TextStyle(
fontSize: 10, fontWeight: FontWeight.bold),
),
],
mainAxisAlignment: MainAxisAlignment.center,
),
const Text(
"-----------------"),
Padding(
padding: const EdgeInsets.only(bottom: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text(
"( 汉字 )",
style: TextStyle(
fontSize: 10, fontWeight: FontWeight.bold),
),
SizedBox(
width: 2,
),
Text(
"رقم الطلب",
style: TextStyle(
fontSize: 10, fontWeight: FontWeight.bold),
),
],
),
),
const SizedBox(
height: 20,
child: Text(
"-----------------------"),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Expanded(
child: Center(
child: Text(
"التفاصيل",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold),
),
),
flex: 6,
),
Expanded(
child: Center(
child: Text(
"السعر ",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold),
),
),
flex: 2,
),
Expanded(
child: Center(
child: Text(
"العدد",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold),
),
),
flex: 2,
),
],
),
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: const ScrollPhysics(),
itemCount: 1,
itemBuilder: (context, index) {
return Card(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Expanded(
child: Center(
child: Text(
"臺灣",
style: TextStyle(fontSize: 10),
),
),
flex: 6,
),
Expanded(
child: Center(
child: Text(
"تجربة عيوني انتة ",
style: TextStyle(fontSize: 10),
),
),
flex: 2,
),
Expanded(
child: Center(
child: Text(
"Test",
style: TextStyle(fontSize: 10),
),
),
flex: 2,
),
],
),
);
},
),
const Text(
"----------"),
],
)),
),
const SizedBox(
height: 25,
),
],
),
],
)),
);
}
}
18 changes: 18 additions & 0 deletions lib/printer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'dart:typed_data';
import 'package:esc_pos_printer/esc_pos_printer.dart';
import 'package:esc_pos_utils/esc_pos_utils.dart';
import 'package:image/image.dart';

Future<void> testReceipt(
NetworkPrinter printer, Uint8List theimageThatC) async {


final Image? image = decodeImage(theimageThatC);
printer.image(image! , align: PosAlign.center);


printer.cut();

}


92 changes: 92 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: printer_test_youtube
description: A new Flutter application.

# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
sdk: ">=2.16.1 <3.0.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter
screenshot: ^1.2.3
esc_pos_printer: ^4.1.0
image: ^3.0.8


# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2

dev_dependencies:
flutter_test:
sdk: flutter

# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^1.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true

# To add assets to your application, add an assets section, like this:
assets:
- images/
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.

# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages

# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages

0 comments on commit b25a86f

Please sign in to comment.