当某个组件外边封装有Tooltip时,点击这个组件或鼠标放上后,会有提示信息。
有的组件本身带有tooltip属性。
/// Flutter code sample for Tooltip
// This example show a basic [Tooltip] which has a [Text] as child.
// [message] contains your label to be shown by the tooltip when
// the child that Tooltip wraps is hovered over on web or desktop. On mobile,
// the tooltip is shown when the widget is long pressed.
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
/// This is the main application widget.
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const Center(
child: MyStatelessWidget(),
),
),
);
}
}
/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const Tooltip(
message: 'I am a Tooltip',
child: Text('Hover over the text to show a tooltip.'),
);
}
}