invitation 0.1.25 copy "invitation: ^0.1.25" to clipboard
invitation: ^0.1.25 copied to clipboard

unlisted

A new Flutter package project.

example/lib/main.dart

import 'dart:ui';

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Invitation Demo'),
    );
  }
}

class Model {
  final String name;
  Model(this.name);
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final inv = Invitation('');
  String id;
  dynamic info;

  TextEditingController _controller = TextEditingController();

  @override
  void initState() {
    super.initState();
    _controller.text = '6666';
  }

  // 生成分享ID
  Future _getId() async {
    setState(() {
      info = '';
      id = '';
    });
    var _id = await inv.gi(params: _controller.text);
    setState(() {
      id = _id;
    });
  }

  // 打开分享链接 url+id
  Future _si() async {
    var _si = await inv.si(id);
    print(_si);
  }

  // 还原分享信息
  Future _reInfo() async {
    var _info = await inv.gr();
    setState(() {
      info = _info;
    });
  }

  Widget _box(Widget widget) => Container(
        width: double.infinity,
        padding: EdgeInsets.all(10.0),
        margin: EdgeInsets.only(top: 10.0),
        child: widget,
        color: Color(0xFF43998E),
      );

  Widget buildItem(String name, Function action) {
    return new Container(
      width: (MediaQuery.of(context).size.width - 30) / 2,
      child: new FlatButton(
        color: Color(0xFFD7E7EB),
        splashColor: Color(0xFF43998E),
        padding: EdgeInsets.symmetric(vertical: 20.0),
        onPressed: action,
        child: new Text(
          name,
          style: TextStyle(color: Color(0xFF43998E), fontSize: 18.0),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      backgroundColor: Color(0xFFeaf2ef),
      body: Padding(
        padding: EdgeInsets.all(10),
        child: new Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            new SizedBox(
                height: MediaQueryData.fromWindow(window).padding.top * 2),
            new Text(
              'Invitation Demo',
              style: TextStyle(color: Color(0xFF43998E), fontSize: 30.0),
            ),
            new SizedBox(height: 10),
            new SingleChildScrollView(
              child: new Padding(
                padding: EdgeInsets.symmetric(horizontal: 0, vertical: 15),
                child: new Wrap(
                  spacing: 10.0,
                  runSpacing: 10.0,
                  alignment: WrapAlignment.start,
                  children: [
                    buildItem('生成邀请码', () {
                      _getId();
                    }),
                    buildItem('还原分享信息', () async {
                      if (id != null) {
                        await _si();
                        await _reInfo();
                      } else {
                        showDialog(
                          context: context,
                          barrierDismissible: false,
                          builder: (BuildContext context) {
                            return AlertDialog(
                              title: Text('无邀请码'),
                              content: Text('是否生成邀请码?'),
                              actions: <Widget>[
                                FlatButton(
                                  onPressed: () => Navigator.pop(context),
                                  child: Text('取消'),
                                ),
                                FlatButton(
                                  onPressed: () async {
                                    await _getId();
                                    await _si();
                                    await _reInfo();
                                    Navigator.pop(context);
                                  },
                                  textColor: Colors.blue,
                                  child: Text('生成'),
                                ),
                              ],
                            );
                          },
                        );
                      }
                    }),
                  ],
                ),
              ),
            ),
            TextField(
              controller: _controller,
              keyboardType: TextInputType.text,
              decoration: InputDecoration(
                contentPadding: EdgeInsets.all(10.0),
                labelText: '要分享的内容',
              ),
              // onChanged: _textFieldChanged,
              autofocus: false,
              onChanged: (value) {
                // setState(() {
                //   _controller.text = value;
                // });
              },
            ),
            _box(Text('ID:$id')),
            _box(Text('Re:$info')),
            _box(Text('$inv')),
          ],
        ),
      ),
    );
  }
}
0
likes
30
pub points
0%
popularity

Publisher

verified publisher6b.ai

A new Flutter package project.

Homepage

License

MIT (LICENSE)

Dependencies

device_info, dio, flutter, package_info

More

Packages that depend on invitation