Hello,
I want to update a SfCartesianChart in an SingleChildScrollView by pulling/dragging the chart in the scrollwiew from the left end to the right. A NotificationListener<ScrollNotification> triggers the update when I get an OverscrollNotification:
the update is working but I get the following error message :
======== Exception caught by gesture library =======================================================
The following assertion was thrown while dispatching a pointer event:
'package:flutter/src/rendering/object.dart': Failed assertion: line 2469 pos 12: 'attached': is not true.
.....
full error message at the end of this post.
When I use a Listview.builder instead of the SfCartesianChart I get no error
I use the last Flutter Syncfusion library with the latest Flutter stable and the build is for Android:
syncfusion_flutter_charts: ^19.4.42
Flutter (Channel stable, 2.8.1)
Can you help me get rid of the error message ?
best regards
jg
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: Scaffold(
appBar: AppBar(
title: const Text('SingleChildScrollView'),
),
body: const Center(
child: SingleChildScrollViewHome(),
),
),
);
}
}
class Data {
Data(this.year, this.value);
final int year;
final double value;
}
Future<List<Data>> dataListFutureFunc(int update) async {
return Future<List<Data>>.delayed(const Duration(seconds: 3), () {
List<Data> data = [
Data(1990, 135 * update.toDouble()),
Data(1991, 134),
Data(1992, 137),
];
return data;
});
}
class SingleChildScrollViewHome extends StatefulWidget {
const SingleChildScrollViewHome({
Key? key,
}) : super(key: key);
@override
_SingleChildScrollViewHome createState() => _SingleChildScrollViewHome();
}
class _SingleChildScrollViewHome extends State<SingleChildScrollViewHome> {
final ScrollController _controller = ScrollController();
DateTime lastUpdated = DateTime.now();
int update = 0;
late Future<List<Data>> _dataListFuture;
@override
void initState() {
_dataListFuture = dataListFutureFunc(update);
super.initState();
}
@override
Widget build(BuildContext context) {
return NotificationListener<ScrollNotification>(
onNotification: (scrollNotification) {
if (scrollNotification is OverscrollNotification) {
if (scrollNotification.overscroll < -5.0) {
final timeUpdate = DateTime.now();
if (lastUpdated
.add(const Duration(seconds: 5))
.isBefore(timeUpdate)) {
lastUpdated = timeUpdate;
setState(() {
update += 1;
_dataListFuture = dataListFutureFunc(update);
});
return false;
}
}
} else {}
return false;
},
child: SingleChildScrollView(
controller: _controller,
scrollDirection: Axis.horizontal,
child: SizedBox(
width: 600,
height: 300,
child: FutureBuilder<List<Data>>(
future: _dataListFuture,
builder: (BuildContext context,
AsyncSnapshot<List<Data>> snapshot) {
print("connectionState: ${snapshot.connectionState}");
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
case ConnectionState.active:
{
return const Center(
child: Text('waiting...'),
);
}
case ConnectionState.done:
{
// NO error message when using a ListView.builder:
// return ListView.builder(
// controller: _controller,
// scrollDirection : Axis.horizontal,
// itemBuilder: (BuildContext context, int index) {
// return Card(child: Text('Item ${snapshot.data?[index].value}'));
// },
// itemCount: snapshot.data?.length,
// );
return SfCartesianChart(
series: <ChartSeries<Data, int>>[
SplineSeries<Data, int>(
dataSource: snapshot.data!,
xValueMapper: (Data d, _) => d.year,
yValueMapper: (Data d, _) => d.value,
)
]);
}
}
}),
),
));
}
}
======== Exception caught by gesture library =======================================================
The following assertion was thrown while dispatching a pointer event:
'package:flutter/src/rendering/object.dart': Failed assertion: line 2469 pos 12: 'attached': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md
When the exception was thrown, this was the stack:
#2 RenderObject.getTransformTo (package:flutter/src/rendering/object.dart:2469:12)
#3 RenderBox.globalToLocal (package:flutter/src/rendering/box.dart:2525:31)
#4 ContainerArea._performPointerUp (package:syncfusion_flutter_charts/src/chart/base/chart_base.dart:3176:39)
#5 ContainerArea.build.<anonymous closure>.<anonymous closure> (package:syncfusion_flutter_charts/src/chart/base/chart_base.dart:2333:21)
#6 RenderPointerListener.handleEvent (package:flutter/src/rendering/proxy_box.dart:2892:27)
#7 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:419:22)
#8 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:322:11)
#9 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:374:7)
#10 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:338:5)
#11 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:296:7)
#12 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:279:7)
#16 _invoke1 (dart:ui/hooks.dart:169:10)
#17 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:293:7)
#18 _dispatchPointerDataPacket (dart:ui/hooks.dart:88:31)
(elided 5 frames from class _AssertionError and dart:async)
Event: PointerUpEvent#66693(position: Offset(400.0, 518.3))
position: Offset(400.0, 518.3)
Target: RenderPointerListener#43c38 DISPOSED
needs compositing
parentData: <none> (can use size)
constraints: BoxConstraints(w=580.0, h=280.0)
size: Size(580.0, 280.0)
behavior: deferToChild
listeners: down, move, up, signal
====================================================================================================
Hi Yuvaraj,
thank you for you interest
regards
Jean
Yuvaraj Gajaraj,
Thank you for your response, I wait for your next weekly patch!
Regards
Jean G.
Hi Yuvaraj Gajaraj,
I have tested version 19.4.47 on my main project and it works perfectly!
Thank you very much for you help!
best regards
Jean G.