Tooltip: Add an example for TooltipTriggerMode.manual and add tests for existing Tooltip examples (#100554)

This commit is contained in:
Taha Tesser
2022-03-26 00:51:06 +02:00
committed by GitHub
parent bfa272ac3e
commit 4526519225
9 changed files with 230 additions and 12 deletions

View File

@@ -11,7 +11,7 @@ void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
static const String _title = 'Tooltip Sample';
@override
Widget build(BuildContext context) {
@@ -20,15 +20,15 @@ class MyApp extends StatelessWidget {
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const Center(
child: MyStatelessWidget(),
child: TooltipSample(),
),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key);
class TooltipSample extends StatelessWidget {
const TooltipSample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {

View File

@@ -11,7 +11,7 @@ void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
static const String _title = 'Tooltip Sample';
@override
Widget build(BuildContext context) {
@@ -20,15 +20,15 @@ class MyApp extends StatelessWidget {
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const Center(
child: MyStatelessWidget(),
child: TooltipSample(),
),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key);
class TooltipSample extends StatelessWidget {
const TooltipSample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {

View File

@@ -11,7 +11,7 @@ void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Flutter Code Sample';
static const String _title = 'Tooltip Sample';
@override
Widget build(BuildContext context) {
@@ -20,15 +20,15 @@ class MyApp extends StatelessWidget {
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const Center(
child: MyStatelessWidget(),
child: TooltipSample(),
),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({Key? key}) : super(key: key);
class TooltipSample extends StatelessWidget {
const TooltipSample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {

View File

@@ -0,0 +1,56 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flutter code sample for Tooltip
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Tooltip Sample';
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: TooltipSample(title: _title),
);
}
}
class TooltipSample extends StatelessWidget {
const TooltipSample({Key? key, required this.title}) : super(key: key);
final String title;
@override
Widget build(BuildContext context) {
final GlobalKey<TooltipState> tooltipkey = GlobalKey<TooltipState>();
return Scaffold(
appBar: AppBar(title: Text(title)),
body: Center(
child: Tooltip(
// Provide a global key with the "TooltipState" type to show
// the tooltip manually when trigger mode is set to manual.
key: tooltipkey,
triggerMode: TooltipTriggerMode.manual,
showDuration: const Duration(seconds: 1),
message: 'I am a Tooltip',
child: const Text('Tap on the FAB'),
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
// Show Tooltip programmatically on button tap.
tooltipkey.currentState?.ensureTooltipVisible();
},
label: const Text('Show Tooltip'),
),
);
}
}