Skip to content

Instantly share code, notes, and snippets.

View Frankdroid7's full-sized avatar
💭
Happily building mobile apps.

Frankdroid7 Frankdroid7

💭
Happily building mobile apps.
View GitHub Profile
final htmlContent = '''
<h1>Heading Example</h1>
<p>This is a paragraph.</p>
<img src="image.jpg" alt="Example Image" />
<blockquote>This is a quote.</blockquote>
<table>
<tbody>
<tr>
<td>Okay <br /></td>
</tr>
Launching lib/main.dart on iPhone 14 Pro in debug mode...
Running Xcode build...
└─Compiling, linking and signing... 2,892ms
Xcode build done. 17.6s
[VERBOSE-2:FlutterDarwinContextMetalImpeller.mm(35)] Using the Impeller rendering backend.
flutter: \^[[31m [error] Error fetching styles: Exception: type 'Null' is not a subtype of type 'String'<…>
[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Exception: Error fetching styles: Exception: type 'Null' is not a subtype of type 'String'
#0 ThetaClient.initialize.<anonymous closure>.<anonymous closure> (package:theta/src/client.dart:21:13)
#1 Left.fold (package:either_dart/src/either.dart:169:15)
#2 ThetaClient.initialize.<anonymous closure> (package:theta/src/client.dart:18:13)
shareTwoPdfFiles(String pdfPath, String secondPdfPath) {
Share.shareXFiles([XFile(pdfPath), XFile(secondPdfPath)]);
}
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:share_plus/share_plus.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter_pdfview/flutter_pdfview.dart';
class PdfView extends StatefulWidget {
class PdfView extends StatefulWidget {
const PdfView({Key? key}) : super(key: key);
@override
State<PdfView> createState() => _PdfViewState();
}
class _PdfViewState extends State<PdfView> {
String? pdfPath;
sharePdfFile(String pdfPath){
Share.shareXFiles([XFile(pdfPath)]);
}
Future storePdfBytesToFile(Uint8List bytes) async {
const filename = 'VueJs CheatSheet';
final dir = await getApplicationDocumentsDirectory();
final file = File('${dir.path}/$filename.pdf');
await file.writeAsBytes(bytes);
setState(() {
pdfPath = file.path;
});
}
Future<Uint8List> getPdfBytesFromUrl(String pdfUrl) async {
final response = await http.get(Uri.parse(pdfUrl));
Uint8List bytes = response.bodyBytes;
return bytes;
}
http: ^0.13.5
share_plus: ^6.3.0
path_provider: ^2.0.11
flutter_pdfview: ^1.2.5
@Frankdroid7
Frankdroid7 / make_file_name.dart
Created August 16, 2022 19:09
A simple function to check through a folder in the device if a file name already exists. If it does, append "(1)" to it to make it unique.
// This function helps to add a string at the back of each file name IF that
// file already exists in the user's file system, so that each file name will
// be unique.
Future<String> makeFileName(String path, String fileName) async {
bool fileExists = await File('$path/$fileName').exists();
if (fileExists) {
int counter = 1;
List newFileExt = fileName.split('.');
String ext = newFileExt[1]; // refers to the file extension.