Skip to content

Commit 378aa7f

Browse files
Merge pull request #1 from merixstudio/feature/example
update example
2 parents a0f2368 + 0db2492 commit 378aa7f

File tree

7 files changed

+732
-466
lines changed

7 files changed

+732
-466
lines changed

example/lib/main.dart

Lines changed: 99 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import 'package:chart/chart.dart';
2-
import 'package:chart/models/chart_layer.dart';
3-
import 'package:example/mocks/chart_mocks.dart';
1+
import 'package:example/pages/bar_page.dart';
2+
import 'package:example/pages/candle_page.dart';
3+
import 'package:example/pages/group_bar_page.dart';
4+
import 'package:example/pages/line_page.dart';
5+
import 'package:example/pages/pie_page.dart';
46
import 'package:flutter/material.dart';
57

68
void main() {
@@ -13,70 +15,113 @@ class MyApp extends StatelessWidget {
1315
@override
1416
Widget build(BuildContext context) {
1517
return MaterialApp(
18+
debugShowCheckedModeBanner: false,
1619
title: 'Chart',
1720
theme: ThemeData(
1821
primarySwatch: Colors.blue,
1922
),
20-
home: const MyHomePage(),
23+
home: const HomePage(),
2124
);
2225
}
2326
}
2427

25-
class MyHomePage extends StatefulWidget {
26-
const MyHomePage({Key? key}) : super(key: key);
28+
class HomePage extends StatelessWidget {
29+
const HomePage({
30+
Key? key,
31+
}) : super(key: key);
2732

28-
@override
29-
State<MyHomePage> createState() => _MyHomePageState();
30-
}
31-
32-
class _MyHomePageState extends State<MyHomePage> {
3333
@override
3434
Widget build(BuildContext context) {
35-
final items = [
36-
ChartMocks.exampleCandle(),
37-
ChartMocks.exampleGroupPie(),
38-
ChartMocks.exampleGroupBar(),
39-
ChartMocks.exampleBar(),
40-
ChartMocks.exampleLine(),
41-
];
4235
return Scaffold(
43-
appBar: AppBar(
44-
leading: Padding(
45-
padding: const EdgeInsets.only(
46-
right: 20.0,
47-
),
48-
child: GestureDetector(
49-
onTap: () => setState(() {}),
50-
child: const Icon(
51-
Icons.refresh,
52-
size: 26.0,
36+
body: Padding(
37+
padding: const EdgeInsets.all(24.0),
38+
child: Column(
39+
crossAxisAlignment: CrossAxisAlignment.stretch,
40+
mainAxisAlignment: MainAxisAlignment.center,
41+
children: [
42+
ElevatedButton(
43+
onPressed: () => Navigator.of(context).push(
44+
MaterialPageRoute(
45+
builder: (_) => const BarPage(),
46+
),
47+
),
48+
style: ElevatedButton.styleFrom(
49+
primary: const Color(0xFF1B0E41),
50+
),
51+
child: const Padding(
52+
padding: EdgeInsets.all(12.0),
53+
child: Text('Bar'),
54+
),
5355
),
54-
),
55-
),
56-
backgroundColor: Colors.transparent,
57-
elevation: 0.0,
58-
),
59-
backgroundColor: const Color(0xFF1B0E41),
60-
body: ListView.separated(
61-
itemBuilder: (_, index) => Center(
62-
child: _buildChart(items[index]),
63-
),
64-
separatorBuilder: (_, __) => const SizedBox(
65-
height: 24.0,
66-
),
67-
itemCount: items.length,
68-
),
69-
);
70-
}
71-
72-
Widget _buildChart(List<ChartLayer> layers) {
73-
return SizedBox(
74-
width: MediaQuery.of(context).size.width * 0.7,
75-
height: 400.0,
76-
child: Chart(
77-
layers: layers,
78-
padding: const EdgeInsets.symmetric(horizontal: 48.0).copyWith(
79-
bottom: 12.0,
56+
const SizedBox(
57+
height: 6.0,
58+
),
59+
ElevatedButton(
60+
onPressed: () => Navigator.of(context).push(
61+
MaterialPageRoute(
62+
builder: (_) => const GroupBarPage(),
63+
),
64+
),
65+
style: ElevatedButton.styleFrom(
66+
primary: const Color(0xFF1B0E41),
67+
),
68+
child: const Padding(
69+
padding: EdgeInsets.all(12.0),
70+
child: Text('Group bar'),
71+
),
72+
),
73+
const SizedBox(
74+
height: 6.0,
75+
),
76+
ElevatedButton(
77+
onPressed: () => Navigator.of(context).push(
78+
MaterialPageRoute(
79+
builder: (_) => const CandlePage(),
80+
),
81+
),
82+
style: ElevatedButton.styleFrom(
83+
primary: const Color(0xFF1B0E41),
84+
),
85+
child: const Padding(
86+
padding: EdgeInsets.all(12.0),
87+
child: Text('Candle'),
88+
),
89+
),
90+
const SizedBox(
91+
height: 6.0,
92+
),
93+
ElevatedButton(
94+
onPressed: () => Navigator.of(context).push(
95+
MaterialPageRoute(
96+
builder: (_) => const LinePage(),
97+
),
98+
),
99+
style: ElevatedButton.styleFrom(
100+
primary: const Color(0xFF1B0E41),
101+
),
102+
child: const Padding(
103+
padding: EdgeInsets.all(12.0),
104+
child: Text('Line'),
105+
),
106+
),
107+
const SizedBox(
108+
height: 6.0,
109+
),
110+
ElevatedButton(
111+
onPressed: () => Navigator.of(context).push(
112+
MaterialPageRoute(
113+
builder: (_) => const PiePage(),
114+
),
115+
),
116+
style: ElevatedButton.styleFrom(
117+
primary: const Color(0xFF1B0E41),
118+
),
119+
child: const Padding(
120+
padding: EdgeInsets.all(12.0),
121+
child: Text('Pie'),
122+
),
123+
),
124+
],
80125
),
81126
),
82127
);

0 commit comments

Comments
 (0)