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
我想将它应用到下面的代码中,如果按下代码中的代码,它会在图例中显示 isVisible true 的图形。下面的示例代码, 填充( 填充: 常量 EdgeInsets.all(14.0), 孩子:墨水井( onTap: () {}, 子:图像.asset( '资产/图像/图片.png', 宽度:20, 身高:30, ), ), ),
我已经在每个按钮上实现了 inkwell,我还不知道实现,目前我正在从 Flutter 文档或其他参考资料中学习
我不确定在哪里可以找到这个图例小部件。下面给出了示例代码。您可以将可见性更改小部件而不是图例放在示例中。
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.
);
}
}