url_preview 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • new50

url_preview #

A new Flutter package project.

Getting Started #

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

[0.0.1] - 6/23/2020. #

  • Added url preview widget.

[0.0.2] - 6/23/2020. #

  • Added example project for url_preview

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:url_preview/url_preview.dart';
import 'package:url_preview_example/models/message.dart';

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

class UrlPreviewExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: ChatScreen());
  }
}

class ChatScreen extends StatefulWidget {
  @override
  _ChatScreenState createState() => _ChatScreenState();
}

class _ChatScreenState extends State<ChatScreen> {
  String message = "";
  final ScrollController listScrollController = ScrollController();
  final TextEditingController textEditingController = TextEditingController();
  _buildMessage(Message message) {
    return message.type == 1
        ? Container(
            constraints: BoxConstraints(minWidth: 100, maxWidth: 250),
            margin: EdgeInsets.only(
              top: 8.0,
              bottom: 8.0,
              left: 80.0,
            ),
            padding: EdgeInsets.symmetric(horizontal: 25.0, vertical: 15.0),
            decoration: BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: [
                    Theme.of(context).primaryColor,
                    Theme.of(context).accentColor
                  ]),
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(15.0),
                bottomLeft: Radius.circular(15.0),
              ),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  message.text,
                  style: TextStyle(
                    color: Colors.white,
                    fontSize: 14.0,
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ],
            ),
          )
        : UrlPreview(
            url: message.text,
            disableTapCallback: true,
          );
  }

  int _getMessageType(String message) {
    if (message?.startsWith('http://') == true ||
        message?.startsWith('https://') == true) {
      return 2;
    }
    return 1;
  }

  _buildMessageComposer() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 8.0),
      height: 70.0,
      color: Colors.white,
      child: Row(
        children: <Widget>[
          IconButton(
            icon: Icon(Icons.photo),
            iconSize: 25.0,
            color: Theme.of(context).primaryColor,
            onPressed: () {},
          ),
          Expanded(
            child: GestureDetector(
              onTap: () {},
              child: TextField(
                controller: textEditingController,
                textCapitalization: TextCapitalization.sentences,
                decoration: InputDecoration.collapsed(
                  hintText: 'Send a message...',
                ),
              ),
            ),
          ),
          IconButton(
            icon: Icon(Icons.send),
            iconSize: 25.0,
            color: Theme.of(context).primaryColor,
            onPressed: () {
              if (textEditingController.text.length != 0) {
                messagesList.add(Message.fromMap({
                  'text': textEditingController.text,
                  'type': _getMessageType(textEditingController.text),
                }));
                textEditingController.clear();
                listScrollController.animateTo(0.0,
                    duration: Duration(milliseconds: 300),
                    curve: Curves.easeOut);
                setState(() {});
              }
            },
          ),
        ],
      ),
    );
  }

  List<Message> messagesList = [
    Message.fromMap({"text": "https://test.com", "type": 2})
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Theme.of(context).primaryColor,
      appBar: AppBar(
        title: Text(
          "URL Preview Example",
          style: TextStyle(
            fontSize: 18.0,
            fontWeight: FontWeight.bold,
          ),
        ),
        elevation: 0.0,
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.more_horiz),
            iconSize: 30.0,
            color: Colors.white,
            onPressed: () {},
          ),
        ],
      ),
      body: GestureDetector(
        child: Column(
          children: <Widget>[
            Expanded(
              child: Container(
                decoration: BoxDecoration(
                  color: Colors.white,
                ),
                child: ClipRRect(
                  child: ListView.builder(
                    controller: listScrollController,
                    padding: EdgeInsets.only(top: 15.0),
                    itemCount: messagesList.length,
                    itemBuilder: (BuildContext context, int index) {
                      return _buildMessage(messagesList[index]);
                    },
                  ),
                ),
              ),
            ),
            _buildMessageComposer(),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  url_preview: ^0.0.3

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:url_preview/url_preview.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
4
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Jul 14, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Windows

Because:

  • package:url_preview/url_preview.dart that imports:
  • package:url_preview/core/meta_data_service.dart that imports:
  • package:url_launcher/url_launcher.dart that declares support for platforms: Android, iOS, Linux, macOS, Web

Package not compatible with SDK dart

Because:

  • url_preview that is a package requiring null.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
html ^0.14.0+3 0.14.0+3
http ^0.12.0+3 0.12.1
url_launcher ^5.4.11 5.5.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
csslib 0.16.1
flutter_web_plugins 0.0.0
http_parser 3.1.4
meta 1.1.8 1.2.2
path 1.7.0
pedantic 1.9.0 1.9.2
platform_detect 1.4.0
plugin_platform_interface 1.0.2
pub_semver 1.4.4
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
url_launcher_linux 0.0.1+1
url_launcher_macos 0.0.1+7
url_launcher_platform_interface 1.0.7
url_launcher_web 0.1.2
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test