Skip to content

Commit

Permalink
Upgrade dependencies, minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
lively-bigyan committed Jan 5, 2021
1 parent 7f97a04 commit 69701d9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 88 deletions.
138 changes: 61 additions & 77 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,102 +14,86 @@ class PdfApp extends StatelessWidget {
appBar: AppBar(
title: const Text("pdf_flutter demo"),
),
body: const PDFListBody(),
body: PDFListBody(),
));
}
}

class PDFListBody extends StatefulWidget {
const PDFListBody({
Key key,
}) : super(key: key);

@override
_PDFListBodyState createState() => _PDFListBodyState();
}

class _PDFListBodyState extends State<PDFListBody> {
File localFile;

@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Column(
children: <Widget>[
const Text("PDF.network(url)"),
PDF.network(
'https://google-developer-training.github.io/android-developer-fundamentals-course-concepts/en/android-developer-fundamentals-course-concepts-en.pdf',
height: 300,
width: 150,
placeHolder: Image.asset("assets/images/pdf.png",
height: 200, width: 100),
),
],
),
const SizedBox(
height: 10,
),
Column(
children: <Widget>[
const Text("PDF.assets(assetname)"),
PDF.assets(
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: const Text("Pdf from asset"),
onPressed: () {
_navigateToPage(
title: "Pdf from asset",
child: PDF.asset(
"assets/pdf/demo.pdf",
height: 300,
width: 150,
placeHolder: Image.asset("assets/images/pdf.png",
height: 200, width: 100),
),
],
),
],
),
const SizedBox(
height: 10,
),
localFile != null
? Column(
children: <Widget>[
const Text("PDF.file(fileName)"),
PDF.file(
localFile,
height: 300,
width: 200,
placeHolder: Image.asset("assets/images/pdf.png",
height: 200, width: 100),
),
],
)
: InkWell(
onTap: () async {
);
},
),
RaisedButton(
child: const Text("Pdf from network"),
onPressed: () {
_navigateToPage(
title: "Pdf from networkUrl",
child: PDF.network(
'https://google-developer-training.github.io/android-developer-fundamentals-course-concepts/en/android-developer-fundamentals-course-concepts-en.pdf',
),
);
},
),
Builder(
builder: (context) {
return RaisedButton(
child: const Text("PDF from file"),
onPressed: () async {
final file = await FilePicker.platform.pickFiles(
allowedExtensions: ['pdf'], type: FileType.custom);
setState(() {
localFile = File(file.files[0].path);
});
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 300,
decoration: BoxDecoration(
color: Colors.cyan,
borderRadius: BorderRadius.circular(20),
),
child: const Center(
child: Text(
"Select PDF from device",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 45, color: Colors.white),
if (file?.files[0]?.path != null) {
_navigateToPage(
title: "PDF from file",
child: PDF.file(
File(file.files[0].path),
),
),
),
),
)
],
);
} else {
Scaffold.of(context).showSnackBar(
const SnackBar(
content: Text("Failed to load Picked file"),
),
);
}
},
);
},
)
],
),
);
}

void _navigateToPage({String title, Widget child}) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Scaffold(
appBar: AppBar(title: Text(title)),
body: Center(child: child),
),
),
);
}
}
26 changes: 15 additions & 11 deletions lib/pdf_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class PDF extends StatefulWidget {
this.file,
this.networkURL,
this.assetsPath,
this.width = 150,
this.height = 250,
this.width = double.maxFinite,
this.height = double.maxFinite,
this.placeHolder,
});

Expand All @@ -25,8 +25,8 @@ class PDF extends StatefulWidget {
/// placeholder : Widget to show when pdf is loading from network.
factory PDF.network(
String url, {
double width = 150,
double height = 250,
double width = double.maxFinite,
double height = double.maxFinite,
Widget placeHolder,
}) {
return PDF._(
Expand All @@ -41,8 +41,8 @@ class PDF extends StatefulWidget {
/// placeholder : [Widget] to show when pdf is loading from network.
factory PDF.file(
File file, {
double width = 150,
double height = 250,
double width = double.maxFinite,
double height = double.maxFinite,
Widget placeHolder,
}) {
return PDF._(
Expand All @@ -56,10 +56,10 @@ class PDF extends StatefulWidget {
/// Load PDF from network
/// assetPath : path like : `assets/pdf/demo.pdf`
/// placeholder : Widget to show when pdf is loading from network.
factory PDF.assets(
factory PDF.asset(
String assetPath, {
double width = 150,
double height = 250,
double width = double.maxFinite,
double height = double.maxFinite,
Widget placeHolder,
}) {
return PDF._(
Expand Down Expand Up @@ -117,7 +117,6 @@ class _PDFState extends State<PDF> {
} else if (widget.assetsPath != null) {
await loadAssetPDF();
}
if (!mounted) return;
setState(() {});
}

Expand Down Expand Up @@ -167,7 +166,12 @@ class _PDFState extends State<PDF> {
child: Container(
height: min(widget.height, widget.width),
width: min(widget.height, widget.width),
child: const CircularProgressIndicator(),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const CircularProgressIndicator(),
],
),
),
),
),
Expand Down

0 comments on commit 69701d9

Please sign in to comment.