Parcourir la source

Subir archivos a 'Carlos'

carlos.perez25 il y a 3 ans
Parent
révision
4e38c23ff4
1 fichiers modifiés avec 109 ajouts et 0 suppressions
  1. 109
    0
      Carlos/main.dart

+ 109
- 0
Carlos/main.dart Voir le fichier

@@ -0,0 +1,109 @@
1
+import 'package:flutter/material.dart';
2
+import 'dart:convert';
3
+import 'package:json_table/json_table.dart';
4
+
5
+class SimpleTable extends StatefulWidget {
6
+  @override
7
+  _SimpleTableState createState() => _SimpleTableState();
8
+}
9
+
10
+class _SimpleTableState extends State<SimpleTable> {
11
+  final String jsonSample =
12
+      '[{"id":"0","name":"Dr.Collazo","Oficina":"A","Phone":"787-522-0123","Espe":"Dentist"},{"id":"1","name":"Dr.Lelolelo","Oficina":"B","Phone":"787-533-4567","Espe":"Dentist"},{"id":"2","name":"Dr.Pepo","Oficina":"C","Phone":"787-544-8910","Espe":"otorrinolaringologo"}]';
13
+  bool toggle = true;
14
+
15
+  @override
16
+  Widget build(BuildContext context) {
17
+    var json = jsonDecode(jsonSample);
18
+    return Scaffold(
19
+      body: Container(
20
+        padding: EdgeInsets.all(16.0),
21
+        child: toggle
22
+            ? Column(
23
+          children: [
24
+            JsonTable(
25
+              json,
26
+              showColumnToggle: true,
27
+              tableHeaderBuilder: (String header) {
28
+                return Container(
29
+                  padding: EdgeInsets.symmetric(
30
+                      horizontal: 8.0, vertical: 4.0),
31
+                  decoration: BoxDecoration(
32
+                      border: Border.all(width: 0.5),
33
+                      color: Colors.grey[300]),
34
+                  child: Text(
35
+                    header,
36
+                    textAlign: TextAlign.center,
37
+                    style: Theme.of(context).textTheme.display1.copyWith(
38
+                        fontWeight: FontWeight.w700,
39
+                        fontSize: 14.0,
40
+                        color: Colors.black87),
41
+                  ),
42
+                );
43
+              },
44
+              tableCellBuilder: (value) {
45
+                return Container(
46
+                  padding: EdgeInsets.symmetric(
47
+                      horizontal: 4.0, vertical: 2.0),
48
+                  decoration: BoxDecoration(
49
+                      border: Border.all(
50
+                          width: 0.5,
51
+                          color: Colors.grey.withOpacity(0.5))),
52
+                  child: Text(
53
+                    value,
54
+                    textAlign: TextAlign.center,
55
+                    style: Theme.of(context).textTheme.display1.copyWith(
56
+                        fontSize: 14.0, color: Colors.grey[900]),
57
+                  ),
58
+                );
59
+              },
60
+              allowRowHighlight: true,
61
+              rowHighlightColor: Colors.yellow[500].withOpacity(0.7),
62
+              paginationRowCount: 20,
63
+            ),
64
+            SizedBox(
65
+              height: 20.0,
66
+            ),
67
+            Text("Simple table which creates table directly from json")
68
+          ],
69
+        )
70
+            : Center(
71
+          child: Text(getPrettyJSONString(jsonSample)),
72
+        ),
73
+      ),
74
+      floatingActionButton: FloatingActionButton(
75
+          child: Icon(Icons.grid_on),
76
+          onPressed: () {
77
+            setState(
78
+                  () {
79
+                toggle = !toggle;
80
+              },
81
+            );
82
+          }),
83
+    );
84
+  }
85
+
86
+  String getPrettyJSONString(jsonObject) {
87
+    JsonEncoder encoder = new JsonEncoder.withIndent('  ');
88
+    String jsonString = encoder.convert(json.decode(jsonObject));
89
+    return jsonString;
90
+  }
91
+}
92
+
93
+void main() => runApp(MyApp());
94
+
95
+class MyApp extends StatelessWidget {
96
+  @override
97
+  Widget build(BuildContext context) {
98
+    return MaterialApp(
99
+      title: 'Flutter Demo',
100
+      theme: ThemeData(
101
+        primarySwatch: Colors.blue,
102
+      ),
103
+      home: SimpleTable(),
104
+    );
105
+  }
106
+}
107
+
108
+
109
+