Skip to content

Commit 402f034

Browse files
author
LavanyaA
authored
Merge pull request #794 from PreethikaSelvam/master
FLUT-834263 - [Others] Moved the volume 2 release to master
2 parents a62d5a4 + bb1cba8 commit 402f034

File tree

2 files changed

+308
-0
lines changed

2 files changed

+308
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/// Package imports
2+
3+
// ignore_for_file: depend_on_referenced_packages
4+
5+
import 'package:flutter/material.dart';
6+
7+
/// DataGrid import
8+
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
9+
10+
/// Local import
11+
import '../../../model/sample_view.dart';
12+
import '../datagridsource/product_datagridsource.dart';
13+
14+
/// Renders column drag and drop data grid sample
15+
class DataGridColumnDragAndDrop extends SampleView {
16+
/// Creates column drag and drop data grid sample
17+
const DataGridColumnDragAndDrop({Key? key}) : super(key: key);
18+
19+
@override
20+
_DataGridColumnDragAndDropState createState() =>
21+
_DataGridColumnDragAndDropState();
22+
}
23+
24+
class _DataGridColumnDragAndDropState extends SampleViewState {
25+
GlobalKey key = GlobalKey();
26+
27+
/// DataGridSource required for SfDataGrid to obtain the row data.
28+
late ProductDataGridSource source;
29+
30+
/// Collection of GridColumn and it required for SfDataGrid
31+
late List<GridColumn> columns;
32+
33+
/// Determine which device the sample loaded
34+
late bool isWebOrDesktop;
35+
36+
@override
37+
void initState() {
38+
super.initState();
39+
isWebOrDesktop = model.isWeb || model.isDesktop;
40+
columns = getColumns();
41+
source = ProductDataGridSource('Column Drag and Drop',
42+
productDataCount: 20, columns: columns);
43+
}
44+
45+
@override
46+
Widget build(BuildContext context) {
47+
return SfDataGrid(
48+
key: key,
49+
source: source,
50+
columns: columns,
51+
allowColumnsDragging: true,
52+
onColumnDragging: (details) {
53+
if (details.action == DataGridColumnDragAction.dropped) {
54+
if (details.to == null) {
55+
return true;
56+
}
57+
final GridColumn rearrangeColumn = columns[details.from];
58+
columns.removeAt(details.from);
59+
columns.insert(details.to!, rearrangeColumn);
60+
}
61+
62+
source.updateDataSource();
63+
return true;
64+
},
65+
gridLinesVisibility: GridLinesVisibility.both,
66+
headerGridLinesVisibility: GridLinesVisibility.both,
67+
);
68+
}
69+
70+
List<GridColumn> getColumns() {
71+
List<GridColumn> columns;
72+
columns = <GridColumn>[
73+
GridColumn(
74+
columnName: 'id',
75+
width: 160,
76+
label: Container(
77+
alignment: Alignment.centerRight,
78+
padding: const EdgeInsets.all(8),
79+
child: const Text(
80+
'Order ID',
81+
overflow: TextOverflow.ellipsis,
82+
),
83+
)),
84+
GridColumn(
85+
columnName: 'productId',
86+
width: 170,
87+
label: Container(
88+
alignment: Alignment.centerRight,
89+
padding: const EdgeInsets.all(8),
90+
child: const Text(
91+
'Product ID',
92+
overflow: TextOverflow.ellipsis,
93+
),
94+
)),
95+
GridColumn(
96+
columnName: 'name',
97+
width: 190,
98+
label: Container(
99+
alignment: Alignment.centerLeft,
100+
padding: const EdgeInsets.all(8),
101+
child: const Text(
102+
'Customer Name',
103+
overflow: TextOverflow.ellipsis,
104+
),
105+
)),
106+
GridColumn(
107+
columnName: 'product',
108+
width: 140,
109+
label: Container(
110+
alignment: Alignment.centerLeft,
111+
padding: const EdgeInsets.all(8),
112+
child: const Text(
113+
'Product',
114+
overflow: TextOverflow.ellipsis,
115+
),
116+
)),
117+
GridColumn(
118+
columnName: 'orderDate',
119+
width: 150,
120+
label: Container(
121+
alignment: Alignment.centerRight,
122+
padding: const EdgeInsets.all(8),
123+
child: const Text(
124+
'Order Date',
125+
overflow: TextOverflow.ellipsis,
126+
),
127+
)),
128+
GridColumn(
129+
columnName: 'quantity',
130+
width: 150,
131+
label: Container(
132+
alignment: Alignment.centerRight,
133+
padding: const EdgeInsets.all(8),
134+
child: const Text(
135+
'Quantity',
136+
overflow: TextOverflow.ellipsis,
137+
),
138+
)),
139+
GridColumn(
140+
columnName: 'city',
141+
width: 140,
142+
label: Container(
143+
alignment: Alignment.centerLeft,
144+
padding: const EdgeInsets.all(8),
145+
child: const Text(
146+
'City',
147+
overflow: TextOverflow.ellipsis,
148+
),
149+
)),
150+
GridColumn(
151+
columnName: 'unitPrice',
152+
width: 140,
153+
label: Container(
154+
alignment: Alignment.centerRight,
155+
padding: const EdgeInsets.all(8),
156+
child: const Text(
157+
'Unit Price',
158+
overflow: TextOverflow.ellipsis,
159+
),
160+
)),
161+
];
162+
return columns;
163+
}
164+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import 'dart:io';
2+
3+
import 'package:flutter/foundation.dart';
4+
import 'package:flutter/material.dart';
5+
import 'package:path_provider/path_provider.dart';
6+
import 'package:syncfusion_flutter_pdf/pdf.dart';
7+
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
8+
9+
import '../../model/sample_view.dart';
10+
11+
import '../pdf/helper/save_file_mobile.dart'
12+
if (dart.library.html) '../pdf/helper/save_file_web.dart';
13+
14+
/// Form filling.
15+
class FormFilling extends SampleView {
16+
/// Form filling.
17+
const FormFilling(Key key) : super(key: key);
18+
19+
@override
20+
_FormFillingState createState() => _FormFillingState();
21+
}
22+
23+
class _FormFillingState extends SampleViewState {
24+
final String _documentPath = 'assets/pdf/form_document.pdf';
25+
final GlobalKey<SfPdfViewerState> _pdfViewerKey = GlobalKey();
26+
final PdfViewerController _pdfViewerController = PdfViewerController();
27+
@override
28+
Widget build(BuildContext context) {
29+
return Scaffold(
30+
appBar: AppBar(
31+
automaticallyImplyLeading: false,
32+
backgroundColor:
33+
((model.themeData.colorScheme.brightness == Brightness.light)
34+
? const Color(0xFFFAFAFA)
35+
: const Color(0xFF424242)),
36+
actions: [
37+
Tooltip(
38+
message: 'Save',
39+
child: IconButton(
40+
color:
41+
(model.themeData.colorScheme.brightness == Brightness.light)
42+
? Colors.black.withOpacity(0.54)
43+
: Colors.white.withOpacity(0.65),
44+
icon: const Icon(Icons.save),
45+
iconSize: 20,
46+
onPressed: () async {
47+
final List<int> savedBytes =
48+
await _pdfViewerController.saveDocument();
49+
_saveDocument(
50+
savedBytes,
51+
'The document was saved and reloaded in the viewer. Also,'
52+
' it was saved at the location ',
53+
'form.pdf');
54+
},
55+
),
56+
),
57+
_divider(),
58+
Tooltip(
59+
message: 'Export Form Data',
60+
child: IconButton(
61+
color:
62+
(model.themeData.colorScheme.brightness == Brightness.light)
63+
? Colors.black.withOpacity(0.54)
64+
: Colors.white.withOpacity(0.65),
65+
icon: const Icon(Icons.outbox),
66+
iconSize: 20,
67+
onPressed: () async {
68+
final List<int> formDataBytes = _pdfViewerController
69+
.exportFormData(dataFormat: DataFormat.xfdf);
70+
_saveDocument(
71+
formDataBytes,
72+
'The exported file was saved in the location ',
73+
'form.xfdf');
74+
},
75+
))
76+
],
77+
),
78+
body: SfPdfViewer.asset(
79+
_documentPath,
80+
key: _pdfViewerKey,
81+
controller: _pdfViewerController,
82+
),
83+
);
84+
}
85+
86+
/// Save document
87+
Future<void> _saveDocument(
88+
List<int> dataBytes, String message, String fileName) async {
89+
if (kIsWeb) {
90+
await FileSaveHelper.saveAndLaunchFile(dataBytes, fileName);
91+
} else {
92+
final Directory directory = await getApplicationSupportDirectory();
93+
final String path = directory.path;
94+
final File file = File('$path/$fileName');
95+
await file.writeAsBytes(dataBytes);
96+
_showDialog(message + path + r'\' + fileName);
97+
}
98+
}
99+
100+
/// Alert dialog for save and export
101+
void _showDialog(String text) {
102+
showDialog<Widget>(
103+
context: context,
104+
builder: (BuildContext context) {
105+
return AlertDialog(
106+
title: const Text('Document saved'),
107+
content: Scrollbar(
108+
child: SingleChildScrollView(
109+
physics: const BouncingScrollPhysics(
110+
parent: AlwaysScrollableScrollPhysics()),
111+
child: Text(text),
112+
),
113+
),
114+
actions: <Widget>[
115+
TextButton(
116+
onPressed: () {
117+
Navigator.of(context).pop();
118+
},
119+
child: const Text('Close'),
120+
)
121+
],
122+
);
123+
});
124+
}
125+
126+
Widget _divider() {
127+
return Padding(
128+
padding: const EdgeInsets.only(left: 8, right: 8),
129+
child: VerticalDivider(
130+
width: 1.0,
131+
// width of vertical divider
132+
thickness: 1.0,
133+
// thickness of vertical divider
134+
indent: 12.0,
135+
// top indent of vertical divider
136+
endIndent: 12.0,
137+
// bottom indent of vertical divider
138+
color: model.themeData.colorScheme.brightness == Brightness.light
139+
? Colors.black.withOpacity(0.24)
140+
: const Color.fromRGBO(255, 255, 255, 0.26),
141+
),
142+
);
143+
}
144+
}

0 commit comments

Comments
 (0)