libv2ray 0.1.1 copy "libv2ray: ^0.1.1" to clipboard
libv2ray: ^0.1.1 copied to clipboard

v2ray plugin for android

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:libv2ray/libv2ray.dart';

void main() {
  runApp(MyApp());
}

var config = """
{
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 1080,
      "protocol": "socks"
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom"
    }
  ]
}
""";

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  int _count = -2;

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await Libv2ray.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('Running on: $_platformVersion\n'),
              TextButton(
                  onPressed: () async {
                    try {
                      await Libv2ray.start(config);
                    } on Error {
                      return;
                    }
                  },
                  child: Text("启动 v2ray")),
              TextButton(
                  onPressed: () async {
                    await Libv2ray.stop();
                  },
                  child: Text("停止 v2ray")),
              TextButton(
                  onPressed: () async {
                    var c = await Libv2ray.status();
                    setState(() {
                      _count = c;
                    });
                  },
                  child: Text("当前状态 ${_count.toString()}")),
            ],
          ),
        ),
      ),
    );
  }
}
10
likes
30
pub points
34%
popularity

Publisher

unverified uploader

v2ray plugin for android

Repository (GitHub)
View/report issues

License

GPL-3.0 (LICENSE)

Dependencies

flutter

More

Packages that depend on libv2ray