print 0.1.0+1

Flutter Android iOS

A simple Flutter plugin for printing images. Currently only Android is supported.

example/lib/main.dart

import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:print/print.dart';
import 'package:path_provider/path_provider.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  QRCode _qRcode;

  @override
  void initState() {
    super.initState();
    _qRcode = QRCode();
  }

  @override
  void dispose() {
    _qRcode?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: StreamBuilder<QRState>(
              stream: _qRcode.state,
              initialData: QRState.EMPTY,
              builder: (context, snapshot){
                switch(snapshot.data){

                  case QRState.EMPTY:
                    return MaterialButton(
                      child: Text("generate qr code"),
                        onPressed: () => _qRcode.downloadQRcode("Hello World!")
                    );
                  case QRState.DOWNLOADING:
                    return CircularProgressIndicator();
                    break;
                  case QRState.DOWNLOADED:
                    return IconButton(icon: Image.memory(_qRcode.image), onPressed: () => _qRcode.print());
                    break;
                  case QRState.PRINTING:
                    return CircularProgressIndicator();
                    break;
                  case QRState.PRINTED:
                    return Text("Printed");
                    break;
                }
              }
          ),
        ),
      ),
    );
  }
}
class QRCode {
  Stream<QRState> state = Stream.empty();
  /*final _state = BehaviorSubject<QRState>.seeded(QRState.EMPTY);
  set _setState(QRState state) => _state.sink.add(state);
  ValueObservable<QRState> get state => _state.stream;*/

  Uint8List image;
  void downloadQRcode(String content) async{
    /*_setState = QRState.DOWNLOADING;
    image = (await get("https://qrcode.tec-it.com/API/QRCode?data=$content"
        "&errorcorrection=H&istransparent=True&size=Small")).bodyBytes;
    _setState = QRState.DOWNLOADED;*/
  }
  void print() async{
    /*_setState = QRState.PRINTING;
    File file = await File("${(await getTemporaryDirectory()).path}/temp_qrcode.png").writeAsBytes(image);
    await printImage(file.path);
    _setState = QRState.PRINTED;*/
  }

  void dispose(){
    //_state.close();
  }
}
enum QRState {
  EMPTY,
  DOWNLOADING,
  DOWNLOADED,
  PRINTING,
  PRINTED
}
0
likes
100
pub points
41%
popularity

A simple Flutter plugin for printing images. Currently only Android is supported.

Homepage

Documentation

API reference

Uploader

development@as-franke.de

License

unknown (LICENSE)

Dependencies

flutter, path_provider

More

Packages that depend on print