Skip to content

Instantly share code, notes, and snippets.

@dmslabsbr
Last active November 14, 2023 20:30
Show Gist options
  • Save dmslabsbr/a0d442ed7c340baf7080b3d1521c7dc4 to your computer and use it in GitHub Desktop.
Save dmslabsbr/a0d442ed7c340baf7080b3d1521c7dc4 to your computer and use it in GitHub Desktop.
Flutter / Flutterflow DynamicIconRender with toolTip
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/actions/actions.dart' as action_blocks;
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/custom_code/actions/index.dart'; // Imports custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
class DynamicIconRender extends StatefulWidget {
const DynamicIconRender({
Key? key,
this.width,
this.height,
required this.iconAmount,
required this.iconType,
required this.iconColor,
this.iconCodePoint,
this.iconFontFamily,
this.iconSize,
this.toolTip,
}) : super(key: key);
final double? width;
final double? height;
final int iconAmount;
final Widget iconType;
final Color iconColor;
final String? iconCodePoint;
final String? iconFontFamily;
final double? iconSize;
final String? toolTip;
// MaterialIcons:
// https://api.flutter.dev/flutter/material/Icons-class.html#constants
//
// iconFontPackage:
String get safeIconCodePoint => iconCodePoint ?? "";
@override
_DynamicIconRenderState createState() => _DynamicIconRenderState();
}
class _DynamicIconRenderState extends State<DynamicIconRender> {
@override
Widget build(BuildContext context) {
print('widget');
print(widget);
print(widget.iconType);
print(widget.safeIconCodePoint);
print(widget.iconColor);
print(widget.iconColor);
print(widget.iconFontFamily);
Widget iconUse = widget.iconType;
String safeIconFontFamily = widget.iconFontFamily ?? 'MaterialIcons';
if (safeIconFontFamily.trim().length == 0) {
safeIconFontFamily = 'MaterialIcons';
}
print(widget.iconFontFamily);
double safeIconSize = widget.iconSize ?? 30;
if (widget.safeIconCodePoint != "") {
print("DynamicIconRender: using icon");
int codIcon = int.parse(widget.safeIconCodePoint, radix: 16);
print(codIcon);
IconData tmpIconData = IconData(codIcon, fontFamily: safeIconFontFamily);
//const tmpIconData = IconData(0xe15b, fontFamily: 'MaterialIcons');
iconUse =
new Icon(tmpIconData, size: safeIconSize, color: widget.iconColor);
}
String toolTip = "";
if (widget.toolTip != null) toolTip = widget.toolTip!;
//IconData tmpIconData = IconData(0xe078, fontFamily: 'MaterialIcons');
//Widget x = new Icon(tmpIconData, size: 30.0, color: Color(0xff4b39ef));
return Container(
width: widget.width,
height: widget.height,
child: Tooltip(
message: toolTip, //"tooltip aqui!"
child: Row(
children: [
for (int i = 0; i < widget.iconAmount; i++)
//widget.iconType
//Icon(widget.iconData, color: widget.iconColor),
iconUse
], // children widget
) // child Row
), // child tooltip
); // Container
}
}
@dmslabsbr
Copy link
Author

Exemple:
Icon Size: 30
IconColor: #bb4242
IconCodePint: 0E001
iconFontFamily: MaterialIcons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment