how to take isVisible true on the legend graph

how to take isVisible true on the legend graph, below is the code

legend: const Legend(
         isVisible: true,
         position: LegendPosition.bottom,
       ),

Later the value will be connected to an inkwell or button to display a line on the graph

I want to apply it to the code below, if the code in the code is pressed it displays a graph of isVisible true in the legend.the example code below, Padding( padding: const EdgeInsets.all(14.0), child: InkWell( onTap: () {}, child: Image.asset( 'asset/images/picture.png', width: 20, height: 30, ), ), ),

I have implemented inkwell on each button, I don't know the implementation yet, currently I am learning from the Flutter documentation or from other references

Upvotes: 0

Views: 32

Answers (1)

dev
dev

Reputation: 152

I am not sure where I could find this Legend widget.Sample code is given below.you can place your visibility changing widget instead of Legend inside the sample.

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(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  bool isVisible = false;

  void _changeVisibility() {
    setState(() {
      isVisible = !isVisible;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
          child: const Legend(
        isVisible: isVisible,
        position: LegendPosition.bottom,
      )),
      floatingActionButton: FloatingActionButton(
        onPressed: _changeVisibility,
        tooltip: 'Make visible',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Upvotes: 0

Related Questions