Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial zoom issue #1863

Open
morvagergely opened this issue Feb 13, 2025 · 0 comments
Open

Initial zoom issue #1863

morvagergely opened this issue Feb 13, 2025 · 0 comments

Comments

@morvagergely
Copy link

Describe the bug
Whenever a chart is built with an initial zoom, the not-zoomed chart is built in the first frame, and the zoom is only applied after that.

To Reproduce

import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _controller = TransformationController(Matrix4.identity()..scale(1.1));

  bool _show = false;

  void _toggle() {
    setState(() {
      _show = !_show;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _show
          ? LineChart(
              LineChartData(lineBarsData: [
                LineChartBarData(
                  spots: [
                    FlSpot(0, 1),
                    FlSpot(1, 2),
                    FlSpot(2, 3),
                    FlSpot(3, 2),
                    FlSpot(4, 1),
                  ],
                )
              ]),
              transformationConfig: FlTransformationConfig(
                transformationController: _controller,
                scaleAxis: FlScaleAxis.free,
              ),
            )
          : SizedBox(),
      floatingActionButton: FloatingActionButton(onPressed: _toggle),
    );
  }
}

Video

Screencast.From.2025-02-13.16-30-47.webm

Versions

  • Flutter: 3.27.3
  • FlChart: 0.70.2

I am planning to open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant