39 lines
1.1 KiB
Dart
39 lines
1.1 KiB
Dart
// State Notifier
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../data/models/bar_data.dart';
|
|
import '../../models/chart_item.dart';
|
|
|
|
class ChartLayoutNotifier extends StateNotifier<List<ChartItem>> {
|
|
ChartLayoutNotifier() : super(_initialCharts);
|
|
|
|
static final List<BarData> _defaultData = [
|
|
BarData(Colors.blue, 10, 5, 8),
|
|
BarData(Colors.orange, 12, 6, 10),
|
|
BarData(Colors.green, 8, 5, 5),
|
|
];
|
|
|
|
static final List<ChartItem> _initialCharts = [
|
|
ChartItem('1', 'Chart A', _defaultData, ['A', 'B', 'C']),
|
|
ChartItem('2', 'Chart B', _defaultData, ['A', 'B', 'C']),
|
|
ChartItem('3', 'Chart C', _defaultData, ['A', 'B', 'C']),
|
|
];
|
|
|
|
void reorder(int oldIndex, int newIndex) {
|
|
final List<ChartItem> newList = List.from(state);
|
|
final item = newList.removeAt(oldIndex);
|
|
newList.insert(newIndex, item);
|
|
state = newList;
|
|
}
|
|
|
|
// void reorder(List<String> newItems) {
|
|
// state = newItems; // or whatever logic you use
|
|
// }
|
|
}
|
|
|
|
final chartLayoutProvider =
|
|
StateNotifierProvider<ChartLayoutNotifier, List<ChartItem>>((ref) {
|
|
return ChartLayoutNotifier();
|
|
});
|