/*
* 描边文字
* */
strokeText(String title,Color strokeColor,Color fillColor, double fontSize){
return Stack(
alignment: Alignment.center,
children: <Widget>[
Text(
title,
style: TextStyle(
fontSize: fontSize,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 1
..color = strokeColor,
),
),
Text(
'$title',
style: TextStyle(
fontSize: fontSize,
color: fillColor,
),
),
],
);
}
//校验网址链接是否以http://或https://开头(这个方法中的链接需要以http开头、.com之类的常见格式结尾)
isUrlValid(String link){
if(link == null || link.isEmpty)
return false;
String pattern = r'^https?://[^\\s]*$'; // 匹配http或https开头,后面跟着非空白字符的字符串
RegExp regex = new RegExp(pattern);
return regex.hasMatch(link);
}
//只校验链接是否以http://或https://开头
isUrlValid(String link){
if(link == null || link.isEmpty)
return false;
if(link.startsWith('http') || link.startsWith('https')){
if(link.contains('://'))
link = link.replaceAll('://', '://');
if(link.startsWith('http://') || link.startsWith('https://')){
return true;
}else{
return false;
}
}else {
return false;
}
}
【flutter描边文字、校验网址链接是否以http://、https://开头】
于 2024-01-31 14:10:40 首次发布
本文介绍了如何在Flutter中使用`strokeText`函数创建带描边效果的文字,并提供了两个版本的URL验证函数`isUrlValid`,分别检查链接是否以http或https开头并确保正确格式。
3162

被折叠的 条评论
为什么被折叠?



