[ad_1]
I am making a operate to print in android and ios with flutter.
I discovered printing whereas trying to find a printing plugin.
I’ve applied pdf creation and printing by way of examples on this plugin.
In Android, it was printed usually, however in IOS, an error occurred.
I assumed this was a problem with the widgets within the MaterialApp and CupertinoApp relying on the platform.
So I set the Widget in keeping with the Platform.
button widget
Widget _wifiButton(BuildContext context){
return Expanded(
flex: 1,
youngster: Container(
width: this.dimension!.width,
top: this.dimension!.top,
alignment: Alignment.heart,
ornament: BoxDecoration(
coloration: Colours.blue,
borderRadius: BorderRadius.round(8.0),
),
youngster: Platform.isAndroid ? TextButton(
onPressed: () async {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => WifiPrint())
);
},
youngster: Textual content(
'W i - F i',
model: TextStyle(
fontWeight: FontWeight.daring,
coloration: Colours.white
),
),
) : CupertinoButton(
onPressed: () async {
Navigator.push(
context,
CupertinoPageRoute(builder: (context) => WifiPrint()),
);
},
youngster: Textual content(
'W i - F i',
model: TextStyle(
fontWeight: FontWeight.daring,
coloration: Colours.white
),
),
),
),
);
}
class WifiPrint
@override
Widget construct(BuildContext context) {
return Platform.isAndroid
? MaterialApp(
house: Scaffold(
physique: PdfPreview(
construct: (format) => _generatePdf(format, context),
),
)
)
: CupertinoApp(
house: CupertinoPageScaffold(
youngster: PdfPreview(
construct: (format) => _generatePdf(format, context),
),
),
);
}
Future<Uint8List> _generatePdf(PdfPageFormat format,
BuildContext context) async {
ultimate pdf = pdfWidget.Doc(model: PdfVersion.pdf_1_5, compress: true);
//ultimate String documentPath = (await getTemporaryDirectory()).path;
for (int nCount = 0; nCount < Supplier.of<ScoreProvider>(context, pay attention: false).scoreImageList.size; nCount++) {
ultimate picture = await imageFromAssetBundle('${Supplier.of<ScoreProvider>(context, pay attention: false).scoreImageList[nCount]}');
pdf.addPage(
pdfWidget.Web page(
pageFormat: format,
construct: (pdfWidget.Context context) {
return pdfWidget.Middle(
youngster: pdfWidget.Padding(
padding: pdfWidget.EdgeInsets.zero,
youngster: pdfWidget.Picture(picture, match: pdfWidget.BoxFit.fill),
),
);
}
)
);
}
return pdf.save();
}
However I acquired the identical error. Are you aware the right way to resolve this downside?
[ad_2]

