3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Flutter アプリからLineを起動

Last updated at Posted at 2020-04-24

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 でプログラムを起動する方法

3
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?