Skip to content

Commit 465bd65

Browse files
Merge pull request syncfusion#86 from dharanidharandharmasivam/master
sample browser changes.
2 parents 41bfbc7 + a5260a1 commit 465bd65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2021
-1011
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.syncfusion.flutter_examples">
3-
3+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
4+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
45
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
56
calls FlutterMain.startInitialization(this); in its onCreate method.
67
In most cases you can leave this as-is, but you if you want to provide
@@ -10,6 +11,15 @@
1011
android:name="io.flutter.app.FlutterApplication"
1112
android:label="Syncfusion Flutter UI Widgets"
1213
android:icon="@mipmap/ic_launcher">
14+
<provider
15+
android:name="androidx.core.content.FileProvider"
16+
android:authorities="${applicationId}.fileProvider"
17+
android:exported="false"
18+
android:grantUriPermissions="true">
19+
<meta-data
20+
android:name="android.support.FILE_PROVIDER_PATHS"
21+
android:resource="@xml/provider_path"/>
22+
</provider>
1323
<activity
1424
android:name=".MainActivity"
1525
android:launchMode="singleTop"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,76 @@
11
package com.syncfusion.flutter_examples;
22

3+
import android.Manifest;
4+
import android.content.Intent;
5+
import android.net.Uri;
6+
import android.os.Build;
37
import android.os.Bundle;
8+
9+
import androidx.core.app.ActivityCompat;
10+
import androidx.core.content.ContextCompat;
11+
import androidx.core.content.FileProvider;
12+
import androidx.core.content.PermissionChecker;
13+
14+
import java.io.File;
15+
416
import io.flutter.app.FlutterActivity;
17+
import io.flutter.plugin.common.MethodCall;
18+
import io.flutter.plugin.common.MethodChannel;
519
import io.flutter.plugins.GeneratedPluginRegistrant;
620

721
public class MainActivity extends FlutterActivity {
822
@Override
923
protected void onCreate(Bundle savedInstanceState) {
1024
super.onCreate(savedInstanceState);
1125
GeneratedPluginRegistrant.registerWith(this);
26+
new MethodChannel(getFlutterView(), "launchFile").setMethodCallHandler(new MethodChannel.MethodCallHandler() {
27+
@Override
28+
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
29+
if (call.method.equals("viewPdf")) {
30+
String path = call.argument("file_path");
31+
if(!checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE)){
32+
requestPermission(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE});
33+
} else {
34+
launchFile(path);
35+
}
36+
}
37+
}
38+
});
39+
}
40+
private void requestPermission(String[] permission){
41+
ActivityCompat.requestPermissions(this, permission, 1);
42+
}
43+
private boolean checkPermission(String permission) {
44+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
45+
return true;
46+
} else {
47+
if (ContextCompat.checkSelfPermission(this, permission) == PermissionChecker.PERMISSION_GRANTED) {
48+
return true;
49+
} else {
50+
return false;
51+
}
52+
}
53+
}
54+
private void launchFile(String filePath){
55+
File file = new File(filePath);
56+
if(file.exists()){
57+
Intent intent = new Intent(Intent.ACTION_VIEW);
58+
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
59+
intent.addCategory("android.intent.category.DEFAULT");
60+
Uri uri = null;
61+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
62+
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
63+
String packageName = this.getPackageName();
64+
uri = FileProvider.getUriForFile(this, packageName + ".fileProvider", new File(filePath));
65+
}else {
66+
uri = Uri.fromFile(file);
67+
}
68+
intent.setDataAndType(uri, "application/pdf");
69+
try{
70+
this.startActivity(intent);
71+
}catch (Exception e){
72+
//Could not launch the file.
73+
}
74+
}
1275
}
1376
}

android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.flutter.plugins;
22

33
import io.flutter.plugin.common.PluginRegistry;
4+
import io.flutter.plugins.pathprovider.PathProviderPlugin;
45
import io.flutter.plugins.urllauncher.UrlLauncherPlugin;
56

67
/**
@@ -11,6 +12,7 @@ public static void registerWith(PluginRegistry registry) {
1112
if (alreadyRegisteredWith(registry)) {
1213
return;
1314
}
15+
PathProviderPlugin.registerWith(registry.registrarFor("io.flutter.plugins.pathprovider.PathProviderPlugin"));
1416
UrlLauncherPlugin.registerWith(registry.registrarFor("io.flutter.plugins.urllauncher.UrlLauncherPlugin"));
1517
}
1618

assets/fonts/Montserrat-Bold.ttf

-255 KB
Binary file not shown.

assets/fonts/Montserrat-Medium.ttf

-254 KB
Binary file not shown.

images/code.png

518 Bytes
Loading

images/info.png

690 Bytes
Loading

ios/Runner/AppDelegate.m

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,43 @@
22
#include "GeneratedPluginRegistrant.h"
33

44
@implementation AppDelegate
5-
5+
UIDocumentInteractionController* _uiController;
66
- (BOOL)application:(UIApplication *)application
77
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
8+
FlutterViewController* controller =(FlutterViewController*) self.window.rootViewController;
9+
10+
FlutterMethodChannel* viewPdfFileChannel = [FlutterMethodChannel methodChannelWithName:@"launchFile" binaryMessenger: controller];
11+
12+
[viewPdfFileChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
13+
if ([@"viewPdf" isEqualToString:call.method]) {
14+
NSString* filePath = call.arguments[@"file_path"];
15+
NSFileManager* fileManager = [NSFileManager defaultManager];
16+
BOOL fileExist = [fileManager fileExistsAtPath:filePath];
17+
if(fileExist){
18+
NSString* fileExtension = [filePath pathExtension];
19+
_uiController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
20+
_uiController.delegate = self;
21+
if([fileExtension isEqualToString:@"pdf"]){
22+
_uiController.UTI = @"com.adobe.pdf";
23+
}
24+
else if([fileExtension isEqualToString:@"txt"]){
25+
_uiController.UTI = @"public.plain-text";
26+
}
27+
else{
28+
NSLog(@"The format %@ is not supported ", filePath);
29+
}
30+
@try {
31+
BOOL isPreview = [_uiController presentPreviewAnimated:YES];
32+
if(!isPreview){
33+
[_uiController presentOpenInMenuFromRect:CGRectMake(200, 20, 100, 100) inView: controller.view animated:YES];
34+
}
35+
36+
} @catch (NSException *exception) {
37+
NSLog(@"%@", exception);
38+
}
39+
}
40+
}
41+
}];
842
[GeneratedPluginRegistrant registerWithRegistry:self];
943
// Override point for customization after application launch.
1044
return [super application:application didFinishLaunchingWithOptions:launchOptions];

ios/Runner/GeneratedPluginRegistrant.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
#import "GeneratedPluginRegistrant.h"
66

7+
#if __has_include(<path_provider/FLTPathProviderPlugin.h>)
8+
#import <path_provider/FLTPathProviderPlugin.h>
9+
#else
10+
@import path_provider;
11+
#endif
12+
713
#if __has_include(<url_launcher/FLTURLLauncherPlugin.h>)
814
#import <url_launcher/FLTURLLauncherPlugin.h>
915
#else
@@ -13,6 +19,7 @@
1319
@implementation GeneratedPluginRegistrant
1420

1521
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
22+
[FLTPathProviderPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTPathProviderPlugin"]];
1623
[FLTURLLauncherPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTURLLauncherPlugin"]];
1724
}
1825

lib/model/model.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class SampleModel extends Model {
139139
Color bottomSheetBackgroundColor = Colors.white;
140140
final bool isTileView = true;
141141
Color cardThemeColor = Colors.white;
142+
bool isWeb = false;
142143

143144
void changeTheme(ThemeData _themeData) {
144145
themeData = _themeData;
@@ -185,8 +186,7 @@ class SampleModel extends Model {
185186
Future<void> updateControl() async {
186187
bool isSample = false;
187188
bool isChild = false;
188-
final String jsonText =
189-
await rootBundle.loadString('lib/sample_details.json');
189+
final String jsonText = await rootBundle.loadString('lib/sample_details.json');
190190
final List<dynamic> controlList = json.decode(jsonText);
191191
List<SubItem> subItems = <SubItem>[];
192192
List<SubItem> subItems1 = <SubItem>[];
@@ -243,7 +243,7 @@ class ChartSampleData {
243243
this.yValue3,
244244
this.pointColor,
245245
this.size,
246-
this.text});
246+
this.text,this.open,this.close});
247247
final dynamic x;
248248
final num y;
249249
final dynamic xValue;
@@ -253,4 +253,6 @@ class ChartSampleData {
253253
final Color pointColor;
254254
final num size;
255255
final String text;
256+
final num open;
257+
final num close;
256258
}

lib/model/view.dart

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class _LayoutPageState extends State<LayoutPage> {
2929
return ScopedModelDescendant<SampleModel>(
3030
rebuildOnChange: true,
3131
builder: (BuildContext context, _, SampleModel model) => Theme(
32-
data: model.themeData,
32+
data: ThemeData(
33+
brightness: model.themeData.brightness,
34+
primaryColor: model.backgroundColor
35+
),
3336
child: SafeArea(
3437
child: DefaultTabController(
3538
length: model.controlList[model.selectedIndex].subItems.length,
@@ -48,9 +51,9 @@ class _LayoutPageState extends State<LayoutPage> {
4851
'card')
4952
? null
5053
: TabBar(
51-
onTap: (int index){
52-
_index = index;
53-
},
54+
onTap: (int index) {
55+
_index = index;
56+
},
5457
indicator: const UnderlineTabIndicator(
5558
borderSide: BorderSide(
5659
width: 5.0,
@@ -65,18 +68,29 @@ class _LayoutPageState extends State<LayoutPage> {
6568
title: Text(
6669
model.controlList[model.selectedIndex].title
6770
.toString(),
68-
style: const TextStyle(
69-
fontWeight: FontWeight.bold,
70-
fontSize: 16.0,
71-
color: Colors.white,
72-
letterSpacing: 0.3)),
71+
style: model.isWeb
72+
? const TextStyle(
73+
fontWeight: FontWeight.bold,
74+
fontSize: 20,
75+
color: Colors.white,
76+
letterSpacing: 0.4)
77+
: const TextStyle(
78+
fontWeight: FontWeight.bold,
79+
fontSize: 16.0,
80+
color: Colors.white,
81+
letterSpacing: 0.3)),
7382
actions: (model.controlList[model.selectedIndex]
7483
.sampleList !=
7584
null &&
7685
model.controlList[model.selectedIndex]
7786
.displayType !=
78-
'card' && model.controlList[model.selectedIndex].sampleList[_index].codeLink != null &&
79-
model.controlList[model.selectedIndex].sampleList[_index].codeLink !='')
87+
'card' &&
88+
model.controlList[model.selectedIndex]
89+
.sampleList[_index].codeLink !=
90+
null &&
91+
model.controlList[model.selectedIndex]
92+
.sampleList[_index].codeLink !=
93+
'')
8094
? <Widget>[
8195
Padding(
8296
padding: const EdgeInsets.fromLTRB(0, 0, 10, 0),
@@ -87,7 +101,10 @@ class _LayoutPageState extends State<LayoutPage> {
87101
icon: Image.asset('images/code.png',
88102
color: Colors.white),
89103
onPressed: () {
90-
launch(model.controlList[model.selectedIndex].sampleList[_index].codeLink);
104+
launch(model
105+
.controlList[model.selectedIndex]
106+
.sampleList[_index]
107+
.codeLink);
91108
},
92109
),
93110
),
@@ -96,7 +113,7 @@ class _LayoutPageState extends State<LayoutPage> {
96113
: null,
97114
),
98115
body: TabBarView(
99-
physics: const NeverScrollableScrollPhysics(),
116+
physics: const NeverScrollableScrollPhysics(),
100117
children:
101118
model.controlList[model.selectedIndex].sampleList !=
102119
null
@@ -168,7 +185,9 @@ class _LayoutPageState extends State<LayoutPage> {
168185
alignment: Alignment.center,
169186
child: Text(
170187
str,
171-
style: TextStyle(fontSize: tabView != 'parent'? 11 : 12, color: Colors.white),
188+
style: TextStyle(
189+
fontSize: tabView != 'parent' ? 11 : 12,
190+
color: Colors.white),
172191
),
173192
),
174193
],
@@ -196,6 +215,7 @@ class _LayoutPageState extends State<LayoutPage> {
196215
itemCount: list.length,
197216
itemBuilder: (BuildContext context, int position) {
198217
final String status = list[position].status;
218+
final SubItem _subitem =list[position];
199219
return Container(
200220
color: model.slidingPanelColor,
201221
padding: const EdgeInsets.all(5.0),
@@ -229,11 +249,17 @@ class _LayoutPageState extends State<LayoutPage> {
229249
softWrap: true,
230250
textScaleFactor: 1,
231251
overflow: TextOverflow.fade,
232-
style: TextStyle(
233-
fontFamily: 'MontserratMedium',
234-
fontSize: 16.0,
235-
color: model.textColor,
236-
letterSpacing: 0.2),
252+
style: model.isWeb
253+
? TextStyle(
254+
fontFamily: 'HeeboMedium',
255+
fontSize: 19.0,
256+
color: model.textColor,
257+
letterSpacing: 0.2)
258+
: TextStyle(
259+
fontFamily: 'HeeboMedium',
260+
fontSize: 16.0,
261+
color: model.textColor,
262+
letterSpacing: 0.2),
237263
),
238264
Container(
239265
child: Row(
@@ -281,14 +307,21 @@ class _LayoutPageState extends State<LayoutPage> {
281307
]),
282308
),
283309
),
284-
InkWell(
285-
onTap: () {},
286-
splashColor: Colors.grey.withOpacity(0.4),
310+
Container(
287311
child: Padding(
288312
padding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
289313
child: SizedBox(
290-
width: double.infinity,
291-
height: 230,
314+
//ignore: avoid_as
315+
width: model.isWeb
316+
? _subitem != null
317+
&& _subitem.key == 'clock_sample'
318+
? (MediaQuery.of(context).size.height *
319+
0.6)
320+
: double.infinity
321+
: double.infinity,
322+
height: model.isWeb
323+
? (MediaQuery.of(context).size.height * 0.6)
324+
: 230,
292325
child: model.sampleWidget[list[position].key]
293326
[0]),
294327
),
@@ -332,7 +365,7 @@ class _LayoutPageState extends State<LayoutPage> {
332365
preferredSize: const Size.fromHeight(46.1),
333366
),
334367
body: TabBarView(
335-
physics: const NeverScrollableScrollPhysics(),
368+
physics: const NeverScrollableScrollPhysics(),
336369
children: _getSamples(
337370
model, list[i].subItems, list[i].displayType)))),
338371
));
@@ -371,7 +404,7 @@ class _LayoutPageState extends State<LayoutPage> {
371404
preferredSize: const Size.fromHeight(46.1),
372405
),
373406
body: TabBarView(
374-
physics: const NeverScrollableScrollPhysics(),
407+
physics: const NeverScrollableScrollPhysics(),
375408
children: list[i].type == 'child'
376409
? _getSamples(
377410
model, list[i].subItems, list[i].displayType)

0 commit comments

Comments
 (0)