Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
## 1.1.0

- Fixed a bug: URL didn't open within the app, but in browser. Solved already

## 2.0.0

- Null-safety
44 changes: 44 additions & 0 deletions example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import 'package:flutter/material.dart';
import 'package:link/link.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Persistent Bottom Navigation Bar example project',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: LinkExample(),
);
}
}

class LinkExample extends StatelessWidget {
const LinkExample({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Container(
child: Link(
child: Text(
'Press here to navigate the flutter main page on the web',
style: TextStyle(
color: Colors.black,
fontSize: 50,
fontWeight: FontWeight.bold,
),
),
url: 'https://flutter.dev/',
),
),
),
),
);
}
}
2 changes: 1 addition & 1 deletion lib/link.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// This library holds just one Material widget
/// It will wrap a child with an InkWell and launch (if possible) the provided URL
/// In case it's not possible to launch the URL, it will call the provided onError function if provided
/// In case it's not possible to launch the URL, it will call the provided onError function if provided
library link;

export 'src/link_base.dart' show Link;
13 changes: 8 additions & 5 deletions lib/src/link_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ import 'package:url_launcher/url_launcher.dart' as Launcher;

/// Wraps a linkable element around child, opening the provided URL as a String
class Link extends StatelessWidget {

final Widget child;
final String url;
final VoidCallback onError;
final VoidCallback? onError;

/// In case the URL is not openable (i.e., scheme is not supported in your device), it won't launch the URL and call the onError callback if provided.
/// Otherwise, the URL will be launched within the app
const Link({Key key, @required this.url, @required this.child, this.onError: null}) : super(key: key);
const Link({Key? key, required this.url, required this.child, this.onError})
: super(key: key);

void _launch(String url) async {
if (await Launcher.canLaunch(url)) {
await Launcher.launch(url, forceWebView: true,);
await Launcher.launch(
url,
forceWebView: true,
);
} else {
if (onError != null) {
onError();
onError!();
}
}
}
Expand Down
Loading