@@ -529,77 +529,85 @@ By default, there will not be any animation.
529
529
{% tabs %}
530
530
{% highlight Dart %}
531
531
532
- late MapZoomPanBehavior zoomPanBehavior;
533
- late MapShapeSource dataSource;
534
- late List<DataModel > data;
535
- late AnimationController animationController;
536
- late Animation animation;
537
-
538
- @override
539
- void initState() {
540
- data = <DataModel >[
541
- DataModel(MapLatLng(28.6139, 77.2090), MapLatLng(39.9042, 116.4074)),
542
- DataModel(MapLatLng(28.7041, 77.1025), MapLatLng(31.2304, 121.4737)),
543
- DataModel(MapLatLng(28.7041, 77.1025), MapLatLng(23.1291, 113.2644)),
544
- DataModel(MapLatLng(28.7041, 77.1025), MapLatLng(22.3193, 114.1694)),
545
- DataModel(MapLatLng(19.0760, 72.8777), MapLatLng(22.3193, 114.1694)),
546
- DataModel(MapLatLng(22.3193, 114.1694), MapLatLng(13.0827, 80.2707)),
547
- ] ;
548
-
549
- dataSource = MapShapeSource.asset(
550
- 'assets/world_map.json',
551
- shapeDataField: 'continent',
552
- );
553
- zoomPanBehavior = MapZoomPanBehavior(
554
- zoomLevel: 4,
555
- focalLatLng: MapLatLng(22.9734, 90.6569),
556
- );
557
-
558
- animationController = AnimationController(
559
- duration: Duration(seconds: 3),
560
- vsync: this,
561
- );
562
- animation = CurvedAnimation(
563
- parent: animationController,
564
- curve: Curves.easeInOut,
565
- );
566
- animationController.forward(from: 0);
567
- super.initState();
568
- }
569
-
570
- @override
571
- void dispose() {
572
- animationController.dispose();
573
- super.dispose();
574
- }
575
-
576
- @override
577
- Widget build(BuildContext context) {
578
- return Scaffold(
579
- body: SfMaps(
580
- layers: [
581
- MapShapeLayer(
582
- source: dataSource,
583
- sublayers: [
584
- MapArcLayer(
585
- arcs: List<MapArc >.generate(
586
- data.length,
587
- (int index) {
588
- return MapArc(
589
- from: data[ index] .from,
590
- to: data[ index] .to,
591
- );
592
- },
593
- ).toSet(),
594
- color: Colors.blue,
595
- animation: animation,
596
- ),
597
- ] ,
598
- zoomPanBehavior: zoomPanBehavior,
599
- ),
600
- ] ,
601
- ),
602
- );
532
+ class AnimationSample extends StatefulWidget {
533
+ const AnimationSample({Key? key}) : super(key: key;
534
+ @override
535
+ State<AnimationSample > createState() => _ AnimationSampleState();
536
+ }
537
+
538
+ class _ AnimationSampleState extends State<AnimationSample > with TickerProviderStateMixin {
539
+ late MapZoomPanBehavior zoomPanBehavior;
540
+ late MapShapeSource dataSource;
541
+ late List<DataModel > data;
542
+ late AnimationController animationController;
543
+ late Animation<double > animation;
544
+
545
+ @override
546
+ void initState() {
547
+ data = <DataModel >[
548
+ DataModel(MapLatLng(28.6139, 77.2090), MapLatLng(39.9042, 116.4074)),
549
+ DataModel(MapLatLng(28.7041, 77.1025), MapLatLng(31.2304, 121.4737)),
550
+ DataModel(MapLatLng(28.7041, 77.1025), MapLatLng(23.1291, 113.2644)),
551
+ DataModel(MapLatLng(28.7041, 77.1025), MapLatLng(22.3193, 114.1694)),
552
+ DataModel(MapLatLng(19.0760, 72.8777), MapLatLng(22.3193, 114.1694)),
553
+ DataModel(MapLatLng(22.3193, 114.1694), MapLatLng(13.0827, 80.2707)),
554
+ ] ;
555
+
556
+ dataSource = MapShapeSource.asset(
557
+ 'assets/world_map.json',
558
+ shapeDataField: 'continent',
559
+ );
560
+ zoomPanBehavior = MapZoomPanBehavior(
561
+ zoomLevel: 4,
562
+ focalLatLng: MapLatLng(22.9734, 90.6569),
563
+ );
564
+
565
+ animationController = AnimationController(
566
+ duration: Duration(seconds: 3),
567
+ vsync: this,
568
+ );
569
+ animation = CurvedAnimation(
570
+ parent: animationController,
571
+ curve: Curves.easeInOut,
572
+ );
573
+ animationController.forward(from: 0);
574
+ super.initState();
575
+ }
576
+
577
+ @override
578
+ void dispose() {
579
+ animationController.dispose();
580
+ super.dispose();
581
+ }
582
+
583
+ @override
584
+ Widget build(BuildContext context) {
585
+ return Scaffold(
586
+ body: SfMaps(
587
+ layers: [
588
+ MapShapeLayer(
589
+ source: dataSource,
590
+ sublayers: [
591
+ MapArcLayer(
592
+ arcs: List<MapArc >.generate(
593
+ data.length,
594
+ (int index) {
595
+ return MapArc(
596
+ from: data[ index] .from,
597
+ to: data[ index] .to,
598
+ );
599
+ },
600
+ ).toSet(),
601
+ color: Colors.blue,
602
+ animation: animation,
603
+ ),
604
+ ] ,
605
+ zoomPanBehavior: zoomPanBehavior,
606
+ ),
607
+ ] ,
608
+ ),
609
+ );
610
+ }
603
611
}
604
612
605
613
class DataModel {
0 commit comments