url_recognizer

Flutter 实现 lorey/social-media-profiles-regexs

此包列出了用于匹配和提取社交媒体配置文件 URL 中信息的正则表达式。因此,如果您在网上某个地方找到此存储库的超链接,例如 https://github.com/lorey/social-media-profiles-regexs/,此存储库中的正则表达式可让您找出它是一个指向存储库的 Github 链接,以及从该 URL 中提取用户名 lorey 和存储库名称 social-media-profiles-regexs。

用法

要使用此插件,请将 url_recognizer 添加到您 pubspec.yaml 文件中的依赖项

dependencies:
  ...
  url_recognizer: ^1.0.0

示例

class _MyAppState extends State<MyApp> {
  final List<SocialUrl> _recognizedSocials = List<SocialUrl>.empty(growable: true);

  @override
  void initState() {
    for (String socialLink in kUrlSamples) {
      SocialUrl? socialUrl = UrlRecognizer.findObject(url: socialLink);
      if (socialUrl != null) {
        _recognizedSocials.add(socialUrl);
      }
    }
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SingleChildScrollView(
          child: Container(
            width: double.infinity,
            padding: EdgeInsets.all(20),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: _recognizedSocials.map((SocialUrl e) => _SocialLinkPreview(socialUrl: e)).toList(),
            ),
          ),
        ),
      ),
    );
  }
}

支持的链接

  • 电子邮件
  • 电话
  • Github
  • Instagram
  • 领英
  • Medium
  • Reddit
  • Skype
  • Snapchat
  • Telegram
  • Twitter
  • YouTube

使用示例

Facebook 个人资料

// Call method
FacebookDetector().build('http://fb.com/peter_parker-miller');

// Get method result
FacebookProfile(
   profile: 'peter_parker-miller',
),

Facebook 个人资料(按 ID)

// Call method
FacebookDetector().build('https://#/profile.php?id=100004123456789');

// Get method result
FacebookProfileById(
   id: '100004123456789',
)

Github 用户

// Call method
FacebookDetector().build('https://github.com/lorey');

// Get method result
GithubUser(
   login: 'lorey',
),

Github 存储库

// Call method
FacebookDetector().build('https://github.com/lorey/socials');

// Get method result
GithubRepo(
   login: 'lorey',
   repo: 'socials',
),

等等…

问题

请在我们的 GitHub 页面上将任何问题、错误或功能请求报告为 issue。

想贡献

如果您想为插件做出贡献(例如,通过改进文档、解决错误或添加很酷的新功能),请向我们发送您的拉取请求。

GitHub

查看 Github