refactor: example app, docs: added gif

This commit is contained in:
iamstanlee 2021-06-04 06:24:35 -07:00
parent 1f9bd54c4f
commit 9d2863089f
11 changed files with 232 additions and 59 deletions

View File

@ -1,3 +1,7 @@
## 1.0.2
- Updated documentation and fixed some minor bugs
## 1.0.1 ## 1.0.1
- Released `v1.0.1` - Released `v1.0.1`

View File

@ -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) [![pub package](https://img.shields.io/pub/v/linkfy_text.svg)](https://pub.dev/packages/linkfy_text)
<!-- ![final](https://user-images.githubusercontent.com/43510799/104180838-2385fd80-5451-11eb-8506-1640b4ea829f.gif) ![gif](ezgif.com-gif-maker.gif)
-->
## Usage ## Usage
@ -44,12 +43,12 @@ Container(
) )
``` ```
| Parameters | Default | Description | | Parameters | Default | Description |
| ----------- | -------------- | ------------------------------------------------------------------------------- | | ----------- | -------------- | ------------------------------------------------------------------------------------------------------------ |
| `textStyle` | `null` | Style applied to the text | | `textStyle` | `null` | Style applied to the text |
| `linkStyle` | `null` | Style applied to the linkified text, defaults to the textStyle | | `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 | | `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` | function with a `Link` paramater called when a link is pressed | | `onTap` | `null` | Callback function with a `Link` paramater called when a link is pressed |
# Contributions # Contributions

View File

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig" #include "Generated.xcconfig"

View File

@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig" #include "Generated.xcconfig"

41
example/ios/Podfile Normal file
View File

@ -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

View File

@ -1,17 +1,19 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:linkfy_text/linkfy_text.dart'; import 'package:linkfy_text/linkfy_text.dart';
var scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
void main() { void main() {
runApp(MyApp()); runApp(MyApp());
} }
var _msgKey = GlobalKey<ScaffoldMessengerState>();
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'linkify_text Demo', title: 'linkify_text Demo',
scaffoldMessengerKey: scaffoldMessengerKey, scaffoldMessengerKey: _msgKey,
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
home: App(), home: App(),
); );
@ -24,13 +26,36 @@ class App extends StatefulWidget {
} }
class _AppState extends State<App> { class _AppState extends State<App> {
void showSnackbar(String msg) { final _textStyle =
scaffoldMessengerKey.currentState!.removeCurrentSnackBar(); GoogleFonts.jetBrainsMono(fontSize: 14, fontWeight: FontWeight.w500);
scaffoldMessengerKey.currentState!
.showSnackBar(SnackBar(content: Text("$msg")));
}
final space = SizedBox(height: 8); final List<Map<String, dynamic?>> _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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -42,44 +67,26 @@ class _AppState extends State<App> {
crossAxisAlignment: CrossAxisAlignment.stretch, crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
Center( Center(
child: LinkifyText( child: Text(
"01. This text contains a url: https://flutter.dev", "LinkifyText",
linkStyle: TextStyle(color: Colors.blue, fontSize: 16), style: _textStyle.copyWith(
onTap: (link) { fontSize: 24,
showSnackbar(link.value!); ),
}, ),
)), ),
space, for (var i = 0; i < _texts.length; i++)
Center( Padding(
child: LinkifyText( padding: EdgeInsets.only(top: 10),
"02. This text contains an email hello@flutter.dev", child: LinkifyText(
linkTypes: [LinkType.email], _texts[i]['text'],
linkStyle: TextStyle(color: Colors.blue, fontSize: 16), textAlign: TextAlign.center,
onTap: (link) { linkTypes: _texts[i]['types'],
showSnackbar(link.value!); textStyle: _textStyle,
}, linkStyle: _textStyle.copyWith(color: Colors.blue),
)), onTap: (link) {
space, showSnackbar("link tapped: ${link.value!}");
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!);
},
)),
], ],
), ),
), ),

View File

@ -43,6 +43,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.15.0" version: "1.15.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
@ -57,6 +64,20 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0" 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: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -67,13 +88,34 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" 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: linkfy_text:
dependency: "direct main" dependency: "direct main"
description: description:
path: ".." path: ".."
relative: true relative: true
source: path source: path
version: "1.0.1" version: "1.0.2"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
@ -95,6 +137,69 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" 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: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -156,6 +261,20 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.0" 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: sdks:
dart: ">=2.12.0 <3.0.0" dart: ">=2.12.0 <3.0.0"
flutter: ">=1.17.0" flutter: ">=1.20.0"

View File

@ -23,6 +23,7 @@ environment:
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
google_fonts: ^2.1.0
linkfy_text: linkfy_text:
path: ../ path: ../

BIN
ezgif.com-gif-maker.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 936 KiB

View File

@ -180,7 +180,7 @@ TextSpan _linkify({
style: linkStyle, style: linkStyle,
recognizer: TapGestureRecognizer() recognizer: TapGestureRecognizer()
..onTap = () { ..onTap = () {
onTap!(link); if (onTap != null) onTap(link);
}, },
), ),
); );

View File

@ -1,10 +1,10 @@
name: linkfy_text name: linkfy_text
description: A lightweight flutter package to linkify texts containing urls, emails and hashtags. 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 homepage: https://github.com/Iamstanlee/linkfy_text
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.17.0" flutter: ">=1.17.0"
dependencies: dependencies: