Files
flutter_wisetronic/lib/widgets/general/text_link.dart
peima 1a578c925d feat: Phase 2 — upgrade deps to null-safe, replace deprecated packages
- pubspec: bump all maintained deps to null-safe latest; flutter pub get resolves
- Remove 12 packages (0-ref or no null-safe): splashscreen, flappy_search_bar,
  searchable_dropdown, share, platform_detect, flutter_inappwebview, countdown,
  gender_selection, flutter_dash, smooth_star_rating, hovering, ffi
- Add flutter_rating_bar
- Keep discontinued-but-null-safe for now (Phase 5): pull_to_refresh, hive, catcher
- New null-safe custom components (API-compatible, callers change only imports):
  utils/countdown.dart, widgets/general/{hover_widget,gender_selection,
  smooth_star_rating,search_bar}.dart
- main.dart: drop dead SplashScreen _buildBody + _to field
- 23 consuming files: swap deprecated imports to local components

Null-safety migration + upgraded-API adaptation = Phase 3.
2026-07-24 03:10:12 +08:00

143 lines
4.0 KiB
Dart

import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_wisetronic/utils/utils.dart';
import 'hover_widget.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../routes.dart';
class TextLink extends StatelessWidget {
final String title;
final String url;
final Color color;
final Color hoverColor;
final double paddingHorizontal;
final double paddingVertical;
final FontWeight fontWeight;
final bool selected;
final bool isLink;
final bool replace;
final bool clearStack;
final bool maintainState;
final bool rootNavigator;
final TransitionType transition;
final bool closeDrawer;
final bool isEmail;
final bool isPhone;
final double fontSize;
final bool isAddress;
final TextOverflow overflow;
final int maxLines;
TextLink(this.title, this.url, {
this.color,
this.hoverColor,
this.paddingHorizontal,
this.paddingVertical,
this.fontWeight,
this.selected,
bool isLink,
bool replace,
bool clearStack,
bool maintainState,
bool rootNavigator,
this.transition,
bool closeDrawer,
bool isEmail,
bool isPhone,
double fontSize,
bool isAddress,
TextOverflow overflow,
int maxLines,
}) :
isLink = isLink ?? false,
replace = replace ?? false,
clearStack = clearStack ?? false,
maintainState = maintainState ?? true,
rootNavigator = rootNavigator ?? false,
closeDrawer = closeDrawer ?? false,
isEmail = isEmail ?? false,
isPhone = isPhone ?? false,
fontSize = fontSize ?? null,
isAddress = isAddress ?? false,
overflow = overflow ?? TextOverflow.ellipsis,
maxLines = maxLines ?? 1;
@override
Widget build(BuildContext context) {
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
child: Container(
padding: EdgeInsets.symmetric(
vertical: paddingVertical ?? 0.0,
horizontal: paddingHorizontal ?? 0.0
),
child: HoverWidget(
child: Text(
title,
style: TextStyle(
color: color ?? Colors.blue,
fontWeight: fontWeight ?? FontWeight.normal,
fontSize: fontSize,
),
overflow: overflow,
maxLines: maxLines,
),
hoverChild: Text(
title,
style: TextStyle(
color: hoverColor ?? Colors.grey,
fontSize: fontSize,
fontWeight: fontWeight ?? FontWeight.normal,
),
overflow: overflow,
maxLines: maxLines,
),
onHover: (event) {
},
),
decoration: BoxDecoration(
border: (selected != null && selected) ? Border(
bottom: BorderSide(
color: color ?? Colors.blue,
width: 3.0,
)
) : null,
),
),
onTap: () async {
if (selected == null || !selected) {
if (isEmail) {
Utils.openEmail(url);
} else if (isPhone) {
Utils.callPhone(url);
} else if (isAddress) {
await launch('https://maps.google.com/?q=${url}');
} else if (!isLink) {
if (closeDrawer) {
Routes.router.pop(context);
}
Routes.router.navigateTo(
context, url,
replace: replace,
clearStack: clearStack,
maintainState: maintainState,
rootNavigator: rootNavigator,
);
} else {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
}
},
),
);
}
}