1
- import 'dart:convert ' ;
2
-
1
+ import 'package:example/pages/custom_column_table.dart ' ;
2
+ import 'package:example/pages/simple_table.dart' ;
3
3
import 'package:flutter/material.dart' ;
4
- import 'package:json_table/json_table.dart' ;
5
4
6
5
void main () => runApp (MyApp ());
7
6
@@ -15,82 +14,38 @@ class MyApp extends StatelessWidget {
15
14
primarySwatch: Colors .purple,
16
15
),
17
16
debugShowCheckedModeBanner: false ,
18
- home: HomePage (),
17
+ home: RootPage (),
19
18
);
20
19
}
21
20
}
22
21
23
- class HomePage extends StatefulWidget {
24
- @override
25
- _HomePageState createState () => _HomePageState ();
26
- }
27
-
28
- class _HomePageState extends State <HomePage > {
29
- final String jsonSample =
30
- '[{"name":"Ram","email":"[email protected] ","age":23,"income":"10Rs","country":"India","area":"abc","day":"Monday","month":"april"},{"name":"Shyam","email":"[email protected] ",'
31
- '"age":28,"income":"30Rs","country":"India","area":"abc","day":"Monday","month":"april"},{"name":"John","email":"[email protected] ","age":33,"income":"15Rs","country":"India",'
32
- '"area":"abc","day":"Monday","month":"april"},{"name":"Ram","email":"[email protected] ","age":23,"income":"10Rs","country":"India","area":"abc","day":"Monday","month":"april"},'
33
- '{"name":"Shyam","email":"[email protected] ","age":28,"income":"30Rs","country":"India","area":"abc","day":"Monday","month":"april"},{"name":"John","email":"[email protected] ",'
34
- '"age":33,"income":"15Rs","country":"India","area":"abc","day":"Monday","month":"april"},{"name":"Ram","email":"[email protected] ","age":23,"income":"10Rs","country":"India",'
35
- '"area":"abc","day":"Monday","month":"april"},{"name":"Shyam","email":"[email protected] ","age":28,"income":"30Rs","country":"India","area":"abc","day":"Monday","month":"april"},'
36
- '{"name":"John","email":"[email protected] ","age":33,"income":"15Rs","country":"India","area":"abc","day":"Monday","month":"april"},{"name":"Ram","email":"[email protected] ","age":23,'
37
- '"income":"10Rs","country":"India","area":"abc","day":"Monday","month":"april"},{"name":"Shyam","email":"[email protected] ","age":28,"income":"30Rs","country":"India","area":"abc",'
38
- '"day":"Monday","month":"april"},{"name":"John","email":"[email protected] ","age":33,"income":"15Rs","country":"India","area":"abc","day":"Monday","month":"april"}]' ;
39
- bool toggle = false ;
22
+ class RootPage extends StatelessWidget {
40
23
41
24
@override
42
25
Widget build (BuildContext context) {
43
- var json = jsonDecode (jsonSample);
44
- return Scaffold (
45
- appBar: AppBar (
46
- title: Text ("Table Widget" ),
47
- ),
48
- body: Container (
49
- padding: EdgeInsets .all (16.0 ),
50
- child: toggle
51
- ? JsonTable (
52
- json,
53
- tableHeaderBuilder: (String header) {
54
- return Container (
55
- padding: EdgeInsets .symmetric (horizontal: 8.0 , vertical: 4.0 ),
56
- decoration: BoxDecoration (border: Border .all (width: 0.5 ), color: Colors .grey[300 ]),
57
- child: Text (
58
- header,
59
- textAlign: TextAlign .center,
60
- style: Theme .of (context).textTheme.display1.copyWith (fontWeight: FontWeight .w700, fontSize: 14.0 , color: Colors .black87),
61
- ),
62
- );
63
- },
64
- tableCellBuilder: (value) {
65
- return Container (
66
- padding: EdgeInsets .symmetric (horizontal: 4.0 , vertical: 2.0 ),
67
- decoration: BoxDecoration (border: Border .all (width: 0.5 , color: Colors .grey.withOpacity (0.5 ))),
68
- child: Text (
69
- value,
70
- textAlign: TextAlign .center,
71
- style: Theme .of (context).textTheme.display1.copyWith (fontSize: 14.0 , color: Colors .grey[900 ]),
72
- ),
73
- );
74
- },
75
- )
76
- : Center (
77
- child: Text (jsonSample),
26
+ return DefaultTabController (
27
+ length: 2 ,
28
+ child: Scaffold (
29
+ appBar: AppBar (
30
+ title: Text ("Table Widget" ),
31
+ bottom: TabBar (
32
+ tabs: < Widget > [
33
+ Tab (
34
+ text: "Simple Table" ,
35
+ ),
36
+ Tab (
37
+ text: "Custom Column Table" ,
78
38
),
39
+ ],
40
+ ),
41
+ ),
42
+ body: TabBarView (
43
+ children: < Widget > [
44
+ SimpleTable (),
45
+ CustomColumnTable (),
46
+ ],
47
+ ),
79
48
),
80
- floatingActionButton: FloatingActionButton (
81
- child: Icon (Icons .grid_on),
82
- onPressed: () {
83
- setState (
84
- () {
85
- toggle = ! toggle;
86
- },
87
- );
88
- }),
89
49
);
90
50
}
91
-
92
- String getPrettyJSONString (jsonObject) {
93
- var encoder = new JsonEncoder .withIndent (" " );
94
- return encoder.convert (jsonObject);
95
- }
96
51
}
0 commit comments