demo
This commit is contained in:
134
lib/done.dart
Normal file
134
lib/done.dart
Normal file
@@ -0,0 +1,134 @@
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:math';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
// called again, and so nothing would appear to happen.
|
||||
_counter++;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: RotatedBox(
|
||||
quarterTurns: 1,
|
||||
child: MyBarChart(),
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyBarChart extends StatelessWidget {
|
||||
final List<ChartData> data = ChartData.exampleData();
|
||||
|
||||
double get maxY => max(
|
||||
data.map((d) => d.gpa).reduce((a, b) => max(a, b)),
|
||||
data.map((d) => d.year).reduce((a, b) => max(a, b)),
|
||||
).toDouble();
|
||||
|
||||
List<BarChartGroupData> _chartGroupData() {
|
||||
return data
|
||||
.map((d) => BarChartGroupData(
|
||||
x: data.indexOf(d),
|
||||
barRods: [
|
||||
BarChartRodData(toY: d.year.toDouble()),
|
||||
BarChartRodData(toY: d.gpa.toDouble())
|
||||
],
|
||||
))
|
||||
.toList();
|
||||
}
|
||||
|
||||
BarChartData _chartData() {
|
||||
return BarChartData(
|
||||
barGroups: _chartGroupData(),
|
||||
maxY: maxY + 0.5,
|
||||
titlesData: FlTitlesData(
|
||||
show: true,
|
||||
topTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
leftTitles: AxisTitles(sideTitles: SideTitles(showTitles: false)),
|
||||
rightTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
reservedSize: 40,
|
||||
showTitles: true,
|
||||
getTitlesWidget: (y, meta) => SideTitleWidget(
|
||||
angle: -1.57079633,
|
||||
child: Text(meta.formattedValue),
|
||||
axisSide: meta.axisSide))),
|
||||
bottomTitles: AxisTitles(
|
||||
sideTitles: SideTitles(
|
||||
reservedSize: 50,
|
||||
showTitles: true,
|
||||
getTitlesWidget: (x, meta) => SideTitleWidget(
|
||||
angle: -1.57079633,
|
||||
child: Text(data[x.floor()].name),
|
||||
axisSide: meta.axisSide))),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BarChart(_chartData());
|
||||
}
|
||||
}
|
||||
|
||||
class ChartData {
|
||||
ChartData({required this.name, required this.gpa, required this.year});
|
||||
|
||||
String name;
|
||||
int gpa;
|
||||
int year;
|
||||
|
||||
static List<ChartData> exampleData() {
|
||||
return [
|
||||
ChartData(name: "John", gpa: 2, year: 1),
|
||||
ChartData(name: "Jane", gpa: 3, year: 2),
|
||||
ChartData(name: "Doe", gpa: 4, year: 3),
|
||||
];
|
||||
}
|
||||
}
|
||||
65
lib/main.dart
Normal file
65
lib/main.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:math';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Center(
|
||||
child: Text("Demo"),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ChartData {
|
||||
ChartData({required this.name, required this.gpa, required this.year});
|
||||
|
||||
String name;
|
||||
int gpa;
|
||||
int year;
|
||||
|
||||
static List<ChartData> exampleData() {
|
||||
return [
|
||||
ChartData(name: "John", gpa: 2, year: 1),
|
||||
ChartData(name: "Jane", gpa: 3, year: 2),
|
||||
ChartData(name: "Doe", gpa: 4, year: 3),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user