Skip to content

Commit 5248ec1

Browse files
authored
Added Google Docs Viewer Application (pranjay-poddar#5055)
* Create main.dart * Add files via upload * Add files via upload * Update README.md
1 parent 15632df commit 5248ec1

File tree

8 files changed

+788
-0
lines changed

8 files changed

+788
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Google Docs Viewer
2+
3+
This project can be used to view google docs directly in a flutter app. Simply provide the url of the doc and see it being loaded for edit/view in the app itself.
4+
5+
## Setting Up
6+
- Create a new flutter project
7+
- Replace it's ```lib``` folder with the ```lib``` folder provided in this repo.
8+
- Add all dependencies provided in the yaml file to your local yaml file of project. ]
9+
- Run the app
10+
11+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This file configures the analyzer, which statically analyzes Dart code to
2+
# check for errors, warnings, and lints.
3+
#
4+
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5+
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6+
# invoked from the command line by running `flutter analyze`.
7+
8+
# The following line activates a set of recommended lints for Flutter apps,
9+
# packages, and plugins designed to encourage good coding practices.
10+
include: package:flutter_lints/flutter.yaml
11+
12+
linter:
13+
# The lint rules applied to this project can be customized in the
14+
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
15+
# included above or to enable additional rules. A list of all available lints
16+
# and their documentation is published at
17+
# https://dart-lang.github.io/linter/lints/index.html.
18+
#
19+
# Instead of disabling a lint rule for the entire project in the
20+
# section below, it can also be suppressed for a single line of code
21+
# or a specific dart file by using the `// ignore: name_of_lint` and
22+
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
23+
# producing the lint.
24+
rules:
25+
# avoid_print: false # Uncomment to disable the `avoid_print` rule
26+
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27+
28+
# Additional information about this file can be found at
29+
# https://dart.dev/guides/language/analysis-options
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
7+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8+
<excludeFolder url="file://$MODULE_DIR$/.idea" />
9+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux/.pub" />
10+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux/build" />
11+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux/.dart_tool" />
12+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/shared_preferences_linux/example/.dart_tool" />
13+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/shared_preferences_linux/example/build" />
14+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/shared_preferences_linux/example/.pub" />
15+
<excludeFolder url="file://$MODULE_DIR$/build" />
16+
<excludeFolder url="file://$MODULE_DIR$/.pub" />
17+
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
18+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/shared_preferences_linux/.pub" />
19+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/shared_preferences_linux/build" />
20+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/shared_preferences_linux/.dart_tool" />
21+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/shared_preferences_windows/.pub" />
22+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/shared_preferences_windows/build" />
23+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/shared_preferences_windows/.dart_tool" />
24+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux/example/build" />
25+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux/example/.dart_tool" />
26+
<excludeFolder url="file://$MODULE_DIR$/linux/flutter/ephemeral/.plugin_symlinks/path_provider_linux/example/.pub" />
27+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/shared_preferences_windows/example/build" />
28+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/shared_preferences_windows/example/.dart_tool" />
29+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/shared_preferences_windows/example/.pub" />
30+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows/example/build" />
31+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows/example/.pub" />
32+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows/example/.dart_tool" />
33+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows/build" />
34+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows/.dart_tool" />
35+
<excludeFolder url="file://$MODULE_DIR$/windows/flutter/ephemeral/.plugin_symlinks/path_provider_windows/.pub" />
36+
</content>
37+
<orderEntry type="sourceFolder" forTests="false" />
38+
<orderEntry type="library" name="Dart SDK" level="project" />
39+
<orderEntry type="library" name="Flutter Plugins" level="project" />
40+
<orderEntry type="library" name="Dart Packages" level="project" />
41+
</component>
42+
</module>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import 'dart:io';
2+
import 'package:http/http.dart' as http;
3+
import 'package:path_provider/path_provider.dart';
4+
import 'package:shared_preferences/shared_preferences.dart';
5+
6+
class ApiServiceProvider {
7+
static String BASE_URL = '';
8+
9+
ApiServiceProvider(String url) {
10+
BASE_URL = url;
11+
print(BASE_URL);
12+
}
13+
14+
static Future<String> loadPDF(String urls) async {
15+
Uri baseurl = Uri.parse(urls);
16+
var response = await http.get(baseurl);
17+
18+
var dir = await getApplicationDocumentsDirectory();
19+
File file = File("${dir.path}/data.pdf");
20+
file.writeAsBytesSync(response.bodyBytes, flush: true);
21+
return file.path;
22+
}
23+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import 'package:devgeeks/pdfloader.dart';
2+
import 'package:flutter/material.dart';
3+
4+
void main() {
5+
runApp(const MaterialApp(debugShowCheckedModeBanner: false, home: MyApp()));
6+
}
7+
8+
class MyApp extends StatefulWidget {
9+
const MyApp({super.key});
10+
11+
@override
12+
State<MyApp> createState() => _MyAppState();
13+
}
14+
15+
class _MyAppState extends State<MyApp> {
16+
late TextEditingController controller;
17+
18+
@override
19+
void initState() {
20+
controller = TextEditingController();
21+
super.initState();
22+
}
23+
24+
@override
25+
void dispose() {
26+
controller.dispose();
27+
super.dispose();
28+
}
29+
30+
@override
31+
Widget build(BuildContext context) {
32+
return MaterialApp(
33+
debugShowCheckedModeBanner: false,
34+
home: Scaffold(
35+
appBar: AppBar(
36+
title: const Text('PDF Loader!'),
37+
centerTitle: true,
38+
),
39+
body: Container(
40+
padding: const EdgeInsets.all(10),
41+
child: Column(
42+
mainAxisAlignment: MainAxisAlignment.center,
43+
crossAxisAlignment: CrossAxisAlignment.center,
44+
children: [
45+
Center(
46+
child: Text(
47+
'Enter your document\'s URL:',
48+
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
49+
),
50+
),
51+
TextField(
52+
controller: controller,
53+
keyboardType: TextInputType.url,
54+
),
55+
const SizedBox(
56+
height: 10,
57+
),
58+
ElevatedButton(
59+
onPressed: () {
60+
Navigator.of(context).push(MaterialPageRoute(
61+
builder: (context) => PdfLoader(
62+
url: controller.text,
63+
)));
64+
},
65+
child: const Text('Fetch Doc/Pdf'))
66+
],
67+
),
68+
),
69+
));
70+
}
71+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_pdfview/flutter_pdfview.dart';
3+
import 'getfile.dart';
4+
5+
class PdfLoader extends StatefulWidget {
6+
final String url;
7+
const PdfLoader({super.key, required this.url});
8+
9+
@override
10+
State<PdfLoader> createState() => _PdfLoaderState();
11+
}
12+
13+
class _PdfLoaderState extends State<PdfLoader> {
14+
String head = 'Loading...';
15+
String localPath = '';
16+
@override
17+
void initState() {
18+
ApiServiceProvider.loadPDF(widget.url).then((value) {
19+
setState(() {
20+
localPath = value;
21+
print('huahuahua');
22+
head = 'PDF Loader';
23+
});
24+
});
25+
super.initState();
26+
}
27+
28+
@override
29+
Widget build(BuildContext context) {
30+
return Scaffold(
31+
appBar: AppBar(
32+
title: Text(head),
33+
centerTitle: true,
34+
),
35+
body: localPath != ''
36+
? PDFView(
37+
fitPolicy: FitPolicy.BOTH,
38+
filePath: localPath,
39+
)
40+
: Center(child: CircularProgressIndicator()),
41+
);
42+
}
43+
}

0 commit comments

Comments
 (0)