163 lines
5.6 KiB
Dart
163 lines
5.6 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:flutter/cupertino.dart';
|
||
|
import 'package:flutter_heatmap_calendar/flutter_heatmap_calendar.dart';
|
||
|
import 'package:konectar_events/utils/util.dart';
|
||
|
|
||
|
class HeatMapExample extends StatefulWidget {
|
||
|
const HeatMapExample({Key? key}) : super(key: key);
|
||
|
|
||
|
@override
|
||
|
State<StatefulWidget> createState() => _HeatMapExample();
|
||
|
}
|
||
|
|
||
|
class _HeatMapExample extends State<HeatMapExample> {
|
||
|
final TextEditingController dateController = TextEditingController();
|
||
|
final TextEditingController heatLevelController = TextEditingController();
|
||
|
|
||
|
bool isOpacityMode = true;
|
||
|
|
||
|
Map<DateTime, int> heatMapDatasets = {
|
||
|
DateTime.parse("20240412"): int.parse("24"),
|
||
|
DateTime.parse("20240413"): int.parse("34"),
|
||
|
DateTime.parse("20240414"): int.parse("14"),
|
||
|
DateTime.parse("20240415"): int.parse("10"),
|
||
|
DateTime.parse("20240422"): int.parse("22"),
|
||
|
DateTime.parse("20240423"): int.parse("16"),
|
||
|
DateTime.parse("20240424"): int.parse("99"),
|
||
|
DateTime.parse("20240512"): int.parse("44"),
|
||
|
DateTime.parse("20240513"): int.parse("33"),
|
||
|
DateTime.parse("20240514"): int.parse("23"),
|
||
|
DateTime.parse("20240515"): int.parse("55"),
|
||
|
DateTime.parse("20240522"): int.parse("90"),
|
||
|
DateTime.parse("20240523"): int.parse("88"),
|
||
|
DateTime.parse("20240524"): int.parse("100"),
|
||
|
};
|
||
|
Map<DateTime, int> heatMapDatasets2 = {
|
||
|
DateTime.parse("20240512"): int.parse("24"),
|
||
|
DateTime.parse("20240513"): int.parse("34"),
|
||
|
DateTime.parse("20240514"): int.parse("14"),
|
||
|
DateTime.parse("20240515"): int.parse("10"),
|
||
|
DateTime.parse("20240522"): int.parse("22"),
|
||
|
DateTime.parse("20240523"): int.parse("16"),
|
||
|
DateTime.parse("20240524"): int.parse("99"),
|
||
|
};
|
||
|
@override
|
||
|
void dispose() {
|
||
|
super.dispose();
|
||
|
dateController.dispose();
|
||
|
heatLevelController.dispose();
|
||
|
}
|
||
|
|
||
|
Widget _textField(final String hint, final TextEditingController controller) {
|
||
|
return Padding(
|
||
|
padding: const EdgeInsets.only(left: 16, right: 20, top: 8.0),
|
||
|
child: TextField(
|
||
|
controller: controller,
|
||
|
decoration: InputDecoration(
|
||
|
enabledBorder: const OutlineInputBorder(
|
||
|
borderSide: BorderSide(color: Color(0xffe7e7e7), width: 1.0)),
|
||
|
focusedBorder: const OutlineInputBorder(
|
||
|
borderSide: BorderSide(color: Color(0xFF20bca4), width: 1.0)),
|
||
|
hintText: hint,
|
||
|
hintStyle: const TextStyle(color: Colors.grey),
|
||
|
isDense: true,
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Column(
|
||
|
children: [
|
||
|
Card(
|
||
|
margin: EdgeInsets.all(isTablet ? 20 : 2),
|
||
|
//elevation: 18,
|
||
|
child: Padding(
|
||
|
padding: EdgeInsets.all(isTablet ? 20 : 2),
|
||
|
child: Row(
|
||
|
mainAxisSize: MainAxisSize.min,
|
||
|
children: [
|
||
|
HeatMap(
|
||
|
startDate: DateTime.parse("2024-04-02"),
|
||
|
endDate: DateTime.parse("2024-05-31"),
|
||
|
size: isTablet ? 20 : 10,
|
||
|
fontSize: 9,
|
||
|
scrollable: true,
|
||
|
colorMode:
|
||
|
isOpacityMode ? ColorMode.opacity : ColorMode.color,
|
||
|
datasets: heatMapDatasets,
|
||
|
colorsets: const {
|
||
|
1: Colors.red,
|
||
|
3: Colors.orange,
|
||
|
5: Colors.yellow,
|
||
|
7: Colors.green,
|
||
|
9: Colors.blue,
|
||
|
11: Colors.indigo,
|
||
|
13: Colors.purple,
|
||
|
},
|
||
|
onClick: (value) {
|
||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||
|
SnackBar(content: Text(value.toString())));
|
||
|
},
|
||
|
),
|
||
|
HeatMap(
|
||
|
startDate: DateTime.parse("2024-05-01"),
|
||
|
endDate: DateTime.parse("2024-05-31"),
|
||
|
scrollable: true,
|
||
|
size: isTablet ? 20 : 10,
|
||
|
fontSize: 9,
|
||
|
colorMode:
|
||
|
isOpacityMode ? ColorMode.opacity : ColorMode.color,
|
||
|
datasets: heatMapDatasets2,
|
||
|
colorsets: const {
|
||
|
1: Colors.red,
|
||
|
3: Colors.orange,
|
||
|
5: Colors.yellow,
|
||
|
7: Colors.green,
|
||
|
9: Colors.blue,
|
||
|
11: Colors.indigo,
|
||
|
13: Colors.purple,
|
||
|
},
|
||
|
onClick: (value) {
|
||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||
|
SnackBar(content: Text(value.toString())));
|
||
|
},
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
// _textField('YYYYMMDD', dateController),
|
||
|
// _textField('Heat Level', heatLevelController),
|
||
|
// ElevatedButton(
|
||
|
// child: const Text('COMMIT'),
|
||
|
// onPressed: () {
|
||
|
// setState(() {
|
||
|
// heatMapDatasets[DateTime.parse(dateController.text)] =
|
||
|
// int.parse(heatLevelController.text);
|
||
|
// });
|
||
|
// },
|
||
|
// ),
|
||
|
|
||
|
// ColorMode/OpacityMode Switch.
|
||
|
// Row(
|
||
|
// mainAxisAlignment: MainAxisAlignment.center,
|
||
|
// children: <Widget>[
|
||
|
// const Text('Color Mode'),
|
||
|
// CupertinoSwitch(
|
||
|
// value: isOpacityMode,
|
||
|
// onChanged: (value) {
|
||
|
// setState(() {
|
||
|
// isOpacityMode = value;
|
||
|
// });
|
||
|
// },
|
||
|
// ),
|
||
|
// const Text('Opacity Mode'),
|
||
|
// ],
|
||
|
// ),
|
||
|
],
|
||
|
);
|
||
|
}
|
||
|
}
|