flutter_link_preview 1.2.9 flutter_link_preview: ^1.2.9 copied to clipboard
This is a URL preview plugin that previews the content of a URL.
import 'package:flutter/material.dart';
import 'package:flutter_link_preview/flutter_link_preview.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
TextEditingController _controller;
@override
void initState() {
_controller = TextEditingController(text: "https://www.baidu.com");
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(15),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: TextField(
controller: _controller,
),
),
RaisedButton(
onPressed: () {
setState(() {});
},
child: const Text("get"),
),
],
),
const SizedBox(height: 15),
ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 500),
child: FlutterLinkPreview(
url: _controller.value.text,
key: ValueKey(_controller.value.text),
titleStyle: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
),
);
}
}