Skip to content

Instantly share code, notes, and snippets.

@happyharis
Created April 7, 2021 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save happyharis/f8cc0f12b4da22b33636c3c6ec6d045e to your computer and use it in GitHub Desktop.
Save happyharis/f8cc0f12b4da22b33636c3c6ec6d045e to your computer and use it in GitHub Desktop.
Hyperlink widget in Flutter web
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'PlayGround',
theme: ThemeData(),
home: HyperText(),
);
}
}
class HyperText extends StatefulWidget {
@override
_HyperTextState createState() => _HyperTextState();
}
class _HyperTextState extends State<HyperText> {
var _hover = false;
var _hover2 = false;
late final _recogniser = TapGestureRecognizer()..onTap = _onTap;
void _onTap() {
launch('https://www.youtube.com/c/learnfluttercode');
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: DefaultTextStyle(
style: TextStyle(fontSize: 50, color: Colors.black),
child: SelectableText.rich(
TextSpan(
children: [
TextSpan(
text: 'Like',
style: TextStyle(
color: _hover ? Colors.white : null,
backgroundColor: _hover ? Colors.blue : null,
),
mouseCursor: SystemMouseCursors.contextMenu,
onEnter: (event) => setState(() => _hover = true),
onExit: (event) => setState(() => _hover = false),
recognizer: _recogniser,
),
TextSpan(
text: ' & ',
),
TextSpan(
text: 'Subscribe',
style: TextStyle(
color: _hover2 ? Colors.white : null,
backgroundColor: _hover2 ? Colors.red : null,
),
mouseCursor: SystemMouseCursors.wait,
onEnter: (event) => setState(() => _hover2 = true),
onExit: (event) => setState(() => _hover2 = false),
recognizer: _recogniser,
),
],
),
),
),
),
);
}
}
name: flutter_playground
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
url_launcher: ^6.0.3
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - howler.js
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment