fix
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/main/model/main_model.dart';
|
||||
import 'package:fcs/pages/widgets/local_text.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_pdfview/flutter_pdfview.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:share/share.dart';
|
||||
|
||||
@@ -45,8 +48,8 @@ class _PaymentPDFScreenState extends State<PaymentPDFScreen>
|
||||
IconButton(
|
||||
icon: Icon(Icons.file_download),
|
||||
onPressed: () async {
|
||||
// var _dir = (await getApplicationDocumentsDirectory()).path;
|
||||
// _downloadFile(widget.path, 'invoice.pdf', _dir);
|
||||
var file = await copyAsset();
|
||||
print('file=> $file');
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
@@ -93,12 +96,6 @@ class _PaymentPDFScreenState extends State<PaymentPDFScreen>
|
||||
);
|
||||
}
|
||||
|
||||
Future<File> _downloadFile(String url, String filename, String dir) async {
|
||||
var req = await http.Client().get(Uri.parse(url));
|
||||
var file = File('$dir/$filename');
|
||||
return file.writeAsBytes(req.bodyBytes);
|
||||
}
|
||||
|
||||
_share(String url) async {
|
||||
MainModel mainModel = Provider.of<MainModel>(context, listen: false);
|
||||
String appUrl = mainModel.setting.appUrl;
|
||||
@@ -108,4 +105,13 @@ class _PaymentPDFScreenState extends State<PaymentPDFScreen>
|
||||
subject: "Invitation to FCS Logistics App",
|
||||
sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);
|
||||
}
|
||||
|
||||
Future<File> copyAsset() async {
|
||||
Directory tempDir = await getTemporaryDirectory();
|
||||
String tempPath = tempDir.path;
|
||||
File tempFile = File('$tempPath/Invoice-A092(A)-32.pdf');
|
||||
ByteData bd = await rootBundle.load('assets/Invoice-A092(A)-32.pdf');
|
||||
await tempFile.writeAsBytes(bd.buffer.asUint8List(), flush: true);
|
||||
return tempFile;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user