Help us understand the problem. What is going on with this article?

Flutter アプリからLineを起動

Flutterのプラグインurl_launcher を使用してSMSを起動したり電話をかけたりする方法は結構お見かけするのですがLINEがなかったので備忘録として残しておきます。

環境

1.プラグインのインストール

プラグインのインストールです。pubspec.yamlを編集します。執筆時点で最新のバージョンを指定しています。

name: 
description: 
  ~省略~

dependencies:
  flutter:
    sdk: flutter
    url_launcher: ^5.4.1

dev_dependencies:
  flutter_test:
    sdk: flutter

2.コード

class Sample extends StatefulWidget {
  @override
  _SampleState createState() => _SampleState();
}

class _SampleState extends State<Sample> {

  @override
  void initState() {
    super.initState();
  }

  final linePath = "https://line.me/R/msg/text/?";


  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('サンプル画面'),
          backgroundColor: Colors.white,
        ),
        body: Center(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            RaisedButton(
              child: Text("Line"),
              color: Colors.green,
              shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(10.0),
              ),
              onPressed: () {
                sendLine(linePath);
              },
            ),
          ],
        ),
      ),
    );
  }
  void _sendLine(String path) async {
    var _status = 'Ready';
    if (await canLaunch(path)) {
      await launch(path);
    } else {
      setState(() {
        print('Chat','Unable to launch url $path');
      });
    }
  }
}

参考文献

LINE URLスキームを使う
URL でプログラムを起動する方法

HisakoIsaka
フリーランスのエンジニアです。主に、Flutterでアプリ開発やWordPressのカスタマイズなどをやってます。kintoneカスタマイズ(JS)はまだまだ勉強中です。
https://plan-follow-up.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした