Skip to content

Instantly share code, notes, and snippets.

@ffkev
Last active May 15, 2024 09:57
Show Gist options
  • Save ffkev/1055a529133c92092991b3a092e3cced to your computer and use it in GitHub Desktop.
Save ffkev/1055a529133c92092991b3a092e3cced to your computer and use it in GitHub Desktop.
Tooltip auto dismiss implementation
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/flutter_flow/flutter_flow_widgets.dart';
import 'package:aligned_tooltip/aligned_tooltip.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
import 'home_page_model.dart';
export 'home_page_model.dart';
class HomePageWidget extends StatefulWidget {
const HomePageWidget({super.key});
@override
State<HomePageWidget> createState() => _HomePageWidgetState();
}
class _HomePageWidgetState extends State<HomePageWidget> {
late HomePageModel _model;
final scaffoldKey = GlobalKey<ScaffoldState>();
@override
void initState() {
super.initState();
_model = createModel(context, () => HomePageModel());
}
@override
void dispose() {
_model.dispose();
super.dispose();
}
//Creating a tool tip controller to manually trigger the tooltip on Gesture tap
AlignedTooltipController tooltipController = AlignedTooltipController(value: TooltipStatus.isHidden);
@override
Widget build(BuildContext context) {
if (isiOS) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarBrightness: Theme.of(context).brightness,
systemStatusBarContrastEnforced: true,
),
);
}
return GestureDetector(
onTap: () => _model.unfocusNode.canRequestFocus
? FocusScope.of(context).requestFocus(_model.unfocusNode)
: FocusScope.of(context).unfocus(),
child: Scaffold(
key: scaffoldKey,
backgroundColor: FlutterFlowTheme.of(context).primaryBackground,
appBar: AppBar(
backgroundColor: FlutterFlowTheme.of(context).primary,
automaticallyImplyLeading: false,
title: Text(
'Page Title',
style: FlutterFlowTheme.of(context).headlineMedium.override(
fontFamily: 'Outfit',
color: Colors.white,
fontSize: 22.0,
),
),
actions: [],
centerTitle: false,
elevation: 2.0,
),
body: SafeArea(
top: true,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
AlignedTooltip(
controller: tooltipController,
content: Padding(
padding: EdgeInsets.all(4.0),
child: Text(
'This is the tooltip',
style: FlutterFlowTheme.of(context).bodyLarge,
)),
offset: 4.0,
isModal: false,
preferredDirection: AxisDirection.down,
borderRadius: BorderRadius.circular(8.0),
backgroundColor: FlutterFlowTheme.of(context).secondaryBackground,
elevation: 4.0,
tailBaseWidth: 24.0,
barrierDismissible: true,
tailLength: 12.0,
waitDuration: Duration(milliseconds: 100),
showDuration: Duration(milliseconds: 500),
// Let's set the trigger mode to manual rather than tap,
// so that we can use the controller to trigger the tooltip from other actions.
triggerMode: TooltipTriggerMode.manual,
// I am using a GestureDetector here to show the tooltip on icon tap manually from the controller.
// Scroll to line 48 to find the tool tip controller
child: GestureDetector(
onTap: () {
tooltipController.showTooltip(autoClose: true);
},
child: Icon(
Icons.settings_outlined,
color: FlutterFlowTheme.of(context).primary,
size: 24.0,
),
),
),
],
),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment