Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust image size with printer 58 mm or 80 mm #1

Open
YouSour opened this issue Dec 12, 2022 · 0 comments
Open

adjust image size with printer 58 mm or 80 mm #1

YouSour opened this issue Dec 12, 2022 · 0 comments

Comments

@YouSour
Copy link

YouSour commented Dec 12, 2022

hi, i just found your video, it is awesome, i wonder how to adjust image size with printer 58mm or 80 mm ? thank in advance
here : example code what i using screenshot package to capture as image

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

class TestPrinting extends StatelessWidget {
  const TestPrinting({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    ThemeData theme = Theme.of(context);
    List<Map<String, dynamic>> headerData = [
      {'លរ': Random().nextInt(100)},
      {'កាលបរិច្ឆេទ': DateFormat('yyyy-MM-dd – kk:mm').format(DateTime.now())},
      {'អ្នកលក់': 'Jhon'},
      {'អតិថជន': 'General'},
      {'លេខទូរស័ព្ទ': 'xxx xxx xxx'}
    ];

    List<String> dataTableHeader = ['ទំនិញ', 'ចំនួន', 'តម្លៃ', 'សរុប'];

    List<Map<String, dynamic>> dataTableBody = [
      {'item': 'item 1', 'qty': 1, 'price': 3.5, 'amount': 0},
      {'item': 'item 2', 'qty': 5, 'price': 2.5, 'amount': 0},
      {'item': 'item 3', 'qty': 1, 'price': 4.5, 'amount': 0},
    ];
    num total = 0;
    for (int i = 0; i < dataTableBody.length; i++) {
      total += dataTableBody[i]['price'] * dataTableBody[i]['qty'];
    }

    String formatTimeStampToString(DateTime dateTime, bool enableTime) {
      String formatStyle = 'dd/MM/yyyy';
      if (enableTime) formatStyle = 'dd/MM/yyyy hh:mm:ss a';
      return DateFormat(formatStyle).format(dateTime);
    }

    return Container(
      width: 300.0,
      child: Column(
        children: [
          Text(
            'RABBIT',
            style: theme.textTheme.headline4,
          ),
          Text(
            '# Street 153 រ៉ាប៊ីតតិចណូឡូជី, Battambang, Cambodia',
            style: theme.textTheme.headline5!.copyWith(fontSize: 16.0),
            textAlign: TextAlign.center,
          ),
          Text(
            'លេខទូរស័ព្ទ ៖ 070 550 880',
            style: theme.textTheme.headline5!.copyWith(fontSize: 16.0),
          ),
          const Divider(
            color: Colors.black,
            thickness: 1.5,
          ),
          Text('Invoice',
              style: theme.textTheme.headline5!
                  .copyWith(decoration: TextDecoration.underline)),
          for (int i = 0; i < headerData.length; i++)
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  headerData[i].keys.first.toUpperCase(),
                  style: theme.textTheme.bodyText2!
                      .copyWith(fontWeight: FontWeight.bold),
                ),
                Text(
                  headerData[i].entries.single.value.toString(),
                  style: theme.textTheme.headline6!,
                ),
              ],
            ),
          const SizedBox(height: 10.0),
          SizedBox(
            width: double.infinity,
            child: Theme(
              data: Theme.of(context).copyWith(dividerColor: Colors.black),
              child: DataTable(
                dividerThickness: 1.5,
                columns: <DataColumn>[
                  for (int i = 0; i < dataTableHeader.length; i++)
                    DataColumn(
                      label: Expanded(
                        child: Text(
                          dataTableHeader[i],
                          style: const TextStyle(
                              color: Colors.black,
                              // fontSize: 18.0,
                              fontStyle: FontStyle.italic,
                              fontWeight: FontWeight.bold),
                        ),
                      ),
                    ),
                ],
                rows: <DataRow>[
                  for (int i = 0; i < dataTableBody.length; i++)
                    DataRow(
                      cells: <DataCell>[
                        DataCell(
                          Text(
                            dataTableBody[i]['item'],
                            style: const TextStyle(fontWeight: FontWeight.bold),
                          ),
                        ),
                        DataCell(
                          Text(
                            dataTableBody[i]['qty'].toString(),
                            style: const TextStyle(fontWeight: FontWeight.bold),
                          ),
                        ),
                        DataCell(
                          Text(
                            dataTableBody[i]['price'].toString(),
                            style: const TextStyle(fontWeight: FontWeight.bold),
                          ),
                        ),
                        DataCell(
                          Text(
                            '${dataTableBody[i]['price'] * dataTableBody[i]['qty']}',
                            style: const TextStyle(fontWeight: FontWeight.bold),
                          ),
                        ),
                      ],
                    ),
                ],
              ),
            ),
          ),
          const Divider(color: Colors.black, thickness: 1.5),
          Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              RichText(
                textAlign: TextAlign.end,
                text: TextSpan(
                    text: 'សរុបទាំងអស់ : ',
                    style: theme.textTheme.bodyText2!
                        .copyWith(fontWeight: FontWeight.bold),
                    children: [
                      TextSpan(
                          text: '$total \$', style: theme.textTheme.headline6),
                    ]),
              )
            ],
          ),
          const Padding(
            padding: EdgeInsets.symmetric(vertical: 10.0),
            child: Text('សូមអរគុណជួបគ្នាម្តងទៀត...'),
          ),
        ],
      ),
    );
  }
}

image :
Simulator Screen Shot - iPad Pro (9 7-inch) - 2022-12-12 at 09 55 57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant