changing View Mode
Closed this issue · 6 comments
When I try to change the ViewMode, errors occur in the design and the data is not displayed correctly, and I tried to add two widget and each of them with a different ViewMode, the same error occurs and the data is not displayed successfully ,
Hi @Hesham-Dev-LY, thank you for open the first issue!
Can you show me a reproducible example?
EDIT
I created the reproduced example. That occurs when switching the view mode state.
I'll try to fix the bug. Thanks.
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:time_chart/time_chart.dart';
// Data must be sorted.
final smallDataList = [
DateTimeRange(
start: DateTime(2021, 2, 24, 23, 15),
end: DateTime(2021, 2, 25, 7, 30),
),
DateTimeRange(
start: DateTime(2021, 2, 22, 1, 55),
end: DateTime(2021, 2, 22, 9, 12),
),
DateTimeRange(
start: DateTime(2021, 2, 20, 0, 25),
end: DateTime(2021, 2, 20, 7, 34),
),
DateTimeRange(
start: DateTime(2021, 2, 17, 21, 23),
end: DateTime(2021, 2, 18, 4, 52),
),
DateTimeRange(
start: DateTime(2021, 2, 13, 6, 32),
end: DateTime(2021, 2, 13, 13, 12),
),
DateTimeRange(
start: DateTime(2021, 2, 1, 9, 32),
end: DateTime(2021, 2, 1, 15, 22),
),
DateTimeRange(
start: DateTime(2021, 1, 22, 12, 10),
end: DateTime(2021, 1, 22, 16, 20),
),
];
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
ViewMode _viewMode = ViewMode.weekly;
@override
Widget build(BuildContext context) {
final sizedBox = const SizedBox(height: 16);
// List<DateTimeRange> bigDataList = getRandomSampleDataList();
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Time chart example app')),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
const Text('Weekly time chart'),
TimeChart(
data: smallDataList,
viewMode: _viewMode,
),
Switch(value: _viewMode == ViewMode.weekly, onChanged: (_) {
setState(() {
_viewMode = _viewMode == ViewMode.weekly ? ViewMode.monthly : ViewMode.weekly;
});
}),
],
),
),
),
),
);
}
}
-
Switching between View models
https://user-images.githubusercontent.com/66942907/129542489-915bc109-21e9-4ba7-8668-021ee05c3a89.mp4 -
adding two TimeChart with different ViewMode
https://user-images.githubusercontent.com/66942907/129542519-c1096e80-77b5-4a11-85f5-54e3b50b76dd.mp4
Hi @Hesham-Dev-LY,
I fixed the first issue, but I don't know the second issue is fixed because I can't reproduce it.
Can you show the example code?
I didn't do anything big, I just put them in one column
TimeChart(
data: data,
timeChartSizeAnimationDuration: Duration(milliseconds: 200),
chartType: ChartType.time,
barColor: mainBlue,
viewMode: ViewMode.weekly,
),
TimeChart(
data: data,
timeChartSizeAnimationDuration: Duration(milliseconds: 200),
chartType: ChartType.time,
barColor: mainBlue,
viewMode: ViewMode.monthly,
)
Well, the below code is working without any bugs. For now, I'll release the plugin that fixed the first issue. And please test again. Thank you.
import 'package:flutter/material.dart';
import 'package:time_chart/time_chart.dart';
// Data must be sorted.
final smallDataList = [
DateTimeRange(
start: DateTime(2021, 2, 24, 23, 15),
end: DateTime(2021, 2, 25, 7, 30),
),
DateTimeRange(
start: DateTime(2021, 2, 22, 1, 55),
end: DateTime(2021, 2, 22, 9, 12),
),
DateTimeRange(
start: DateTime(2021, 2, 20, 0, 25),
end: DateTime(2021, 2, 20, 7, 34),
),
DateTimeRange(
start: DateTime(2021, 2, 17, 21, 23),
end: DateTime(2021, 2, 18, 4, 52),
),
DateTimeRange(
start: DateTime(2021, 2, 13, 6, 32),
end: DateTime(2021, 2, 13, 13, 12),
),
DateTimeRange(
start: DateTime(2021, 2, 1, 9, 32),
end: DateTime(2021, 2, 1, 15, 22),
),
DateTimeRange(
start: DateTime(2021, 1, 22, 12, 10),
end: DateTime(2021, 1, 22, 16, 20),
),
];
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Time chart example app')),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
const Text('Weekly time chart'),
TimeChart(
data: smallDataList,
timeChartSizeAnimationDuration: Duration(milliseconds: 200),
chartType: ChartType.time,
viewMode: ViewMode.weekly,
),
TimeChart(
data: smallDataList,
timeChartSizeAnimationDuration: Duration(milliseconds: 200),
chartType: ChartType.time,
viewMode: ViewMode.monthly,
),
],
),
),
),
),
);
}
}
I've released version 0.2.7.