diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c88af5..20e7170 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.2 + +- Updated documentation and fixed some minor bugs + ## 1.0.1 - Released `v1.0.1` diff --git a/README.md b/README.md index ddd40c6..480f67f 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,7 @@ A lightweight flutter package to linkify texts containing urls, emails and hasht [![pub package](https://img.shields.io/pub/v/linkfy_text.svg)](https://pub.dev/packages/linkfy_text) - +![gif](ezgif.com-gif-maker.gif) ## Usage @@ -44,12 +43,12 @@ Container( ) ``` -| Parameters | Default | Description | -| ----------- | -------------- | ------------------------------------------------------------------------------- | -| `textStyle` | `null` | Style applied to the text | -| `linkStyle` | `null` | Style applied to the linkified text, defaults to the textStyle | -| `linkTypes` | `LinkType.url` | A list of `LinkTypes` to be linkified in the text either a hashtag,email or url | -| `onTap` | `null` | function with a `Link` paramater called when a link is pressed | +| Parameters | Default | Description | +| ----------- | -------------- | ------------------------------------------------------------------------------------------------------------ | +| `textStyle` | `null` | Style applied to the text | +| `linkStyle` | `null` | Style applied to the linkified text, defaults to the textStyle | +| `linkTypes` | `LinkType.url` | A list of `LinkTypes` used to override the links to be linkified in the text either a hashtag, email or url. | +| `onTap` | `null` | Callback function with a `Link` paramater called when a link is pressed | # Contributions diff --git a/example/ios/Flutter/Debug.xcconfig b/example/ios/Flutter/Debug.xcconfig index 592ceee..ec97fc6 100644 --- a/example/ios/Flutter/Debug.xcconfig +++ b/example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/example/ios/Flutter/Release.xcconfig b/example/ios/Flutter/Release.xcconfig index 592ceee..c4855bf 100644 --- a/example/ios/Flutter/Release.xcconfig +++ b/example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/example/ios/Podfile b/example/ios/Podfile new file mode 100644 index 0000000..1e8c3c9 --- /dev/null +++ b/example/ios/Podfile @@ -0,0 +1,41 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '9.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/example/lib/main.dart b/example/lib/main.dart index 7fe07aa..7d1fe9b 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,17 +1,19 @@ import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; import 'package:linkfy_text/linkfy_text.dart'; -var scaffoldMessengerKey = GlobalKey(); void main() { runApp(MyApp()); } +var _msgKey = GlobalKey(); + class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'linkify_text Demo', - scaffoldMessengerKey: scaffoldMessengerKey, + scaffoldMessengerKey: _msgKey, debugShowCheckedModeBanner: false, home: App(), ); @@ -24,13 +26,36 @@ class App extends StatefulWidget { } class _AppState extends State { - void showSnackbar(String msg) { - scaffoldMessengerKey.currentState!.removeCurrentSnackBar(); - scaffoldMessengerKey.currentState! - .showSnackBar(SnackBar(content: Text("$msg"))); - } + final _textStyle = + GoogleFonts.jetBrainsMono(fontSize: 14, fontWeight: FontWeight.w500); - final space = SizedBox(height: 8); + final List> _texts = [ + { + "text": "O1. This text contains a url: https://flutter.dev", + "types": null + }, + { + "text": "O2. This text contains an email address: example@app.com", + "types": [LinkType.email] + }, + { + "text": "O3. This text contains an #hashtag", + "types": [LinkType.hashTag] + }, + { + "text": + "O4. This text contains a url: https://flutter.dev, An email example@app.com and #hashtag", + "types": [LinkType.email, LinkType.url, LinkType.hashTag] + }, + ]; + + void showSnackbar(String msg) { + _msgKey.currentState!.removeCurrentSnackBar(); + _msgKey.currentState!.showSnackBar(SnackBar( + content: Text("$msg", style: _textStyle), + behavior: SnackBarBehavior.floating, + )); + } @override Widget build(BuildContext context) { @@ -42,44 +67,26 @@ class _AppState extends State { crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Center( - child: LinkifyText( - "01. This text contains a url: https://flutter.dev", - linkStyle: TextStyle(color: Colors.blue, fontSize: 16), - onTap: (link) { - showSnackbar(link.value!); - }, - )), - space, - Center( - child: LinkifyText( - "02. This text contains an email hello@flutter.dev", - linkTypes: [LinkType.email], - linkStyle: TextStyle(color: Colors.blue, fontSize: 16), - onTap: (link) { - showSnackbar(link.value!); - }, - )), - space, - Center( - child: LinkifyText( - "03. This contains an #hashtag", - linkTypes: [LinkType.hashTag], - linkStyle: TextStyle(color: Colors.blue, fontSize: 16), - onTap: (link) { - showSnackbar(link.value!); - }, - )), - space, - Center( - child: LinkifyText( - "04. Flutter is #trending, goto https://flutter.dev to check it out. hey@pub.dev", - textAlign: TextAlign.center, - linkTypes: [LinkType.hashTag, LinkType.url, LinkType.email], - linkStyle: TextStyle(color: Colors.blue, fontSize: 16), - onTap: (link) { - showSnackbar(link.value!); - }, - )), + child: Text( + "LinkifyText", + style: _textStyle.copyWith( + fontSize: 24, + ), + ), + ), + for (var i = 0; i < _texts.length; i++) + Padding( + padding: EdgeInsets.only(top: 10), + child: LinkifyText( + _texts[i]['text'], + textAlign: TextAlign.center, + linkTypes: _texts[i]['types'], + textStyle: _textStyle, + linkStyle: _textStyle.copyWith(color: Colors.blue), + onTap: (link) { + showSnackbar("link tapped: ${link.value!}"); + }, + )), ], ), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 436d1bd..42a870d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -43,6 +43,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0" + crypto: + dependency: transitive + description: + name: crypto + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.1" cupertino_icons: dependency: "direct main" description: @@ -57,6 +64,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.0" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + file: + dependency: transitive + description: + name: file + url: "https://pub.dartlang.org" + source: hosted + version: "6.1.1" flutter: dependency: "direct main" description: flutter @@ -67,13 +88,34 @@ packages: description: flutter source: sdk version: "0.0.0" + google_fonts: + dependency: "direct main" + description: + name: google_fonts + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + http: + dependency: transitive + description: + name: http + url: "https://pub.dartlang.org" + source: hosted + version: "0.13.3" + http_parser: + dependency: transitive + description: + name: http_parser + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0" linkfy_text: dependency: "direct main" description: path: ".." relative: true source: path - version: "1.0.1" + version: "1.0.2" matcher: dependency: transitive description: @@ -95,6 +137,69 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + path_provider: + dependency: transitive + description: + name: path_provider + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.2" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + pedantic: + dependency: transitive + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.11.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + process: + dependency: transitive + description: + name: process + url: "https://pub.dartlang.org" + source: hosted + version: "4.2.1" sky_engine: dependency: transitive description: flutter @@ -156,6 +261,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.5" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" sdks: dart: ">=2.12.0 <3.0.0" - flutter: ">=1.17.0" + flutter: ">=1.20.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index d21de0e..05a20bd 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -23,6 +23,7 @@ environment: dependencies: flutter: sdk: flutter + google_fonts: ^2.1.0 linkfy_text: path: ../ diff --git a/ezgif.com-gif-maker.gif b/ezgif.com-gif-maker.gif new file mode 100644 index 0000000..b1c4aac Binary files /dev/null and b/ezgif.com-gif-maker.gif differ diff --git a/lib/src/linkify.dart b/lib/src/linkify.dart index 1198841..90bcd95 100644 --- a/lib/src/linkify.dart +++ b/lib/src/linkify.dart @@ -180,7 +180,7 @@ TextSpan _linkify({ style: linkStyle, recognizer: TapGestureRecognizer() ..onTap = () { - onTap!(link); + if (onTap != null) onTap(link); }, ), ); diff --git a/pubspec.yaml b/pubspec.yaml index 2e3a04e..b59dd4f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: linkfy_text description: A lightweight flutter package to linkify texts containing urls, emails and hashtags. -version: 1.0.1 +version: 1.0.2 homepage: https://github.com/Iamstanlee/linkfy_text environment: - sdk: '>=2.12.0 <3.0.0' + sdk: ">=2.12.0 <3.0.0" flutter: ">=1.17.0" dependencies: