tdlib 1.2.1 tdlib: ^1.2.1 copied to clipboard
Flutter Plugin for TDLib.a complete tdlib-tdjson binding package.
/*
* just a example! client creator :)
*/
import 'package:flutter/material.dart';
import 'package:tdlib/td_client.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
Widget build(BuildContext context) { // ignore: annotate_overrides
return MaterialApp(
title: 'TDLib Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter TDLib Example'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
/*
Here we go!
*/
int clientId = 0;
void _clientCreator() async {
/*
Here we renew!
*/
final oldClientId = clientId;
final newClientId = await TdClient.createClient();
setState(() {
clientId = newClientId;
});
// closing after renewing! just to get NEW client identifier.
if (oldClientId != 0) {
await TdClient.destroyClient(oldClientId);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'TDLib Client ID\n$clientId',
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _clientCreator,
tooltip: 'creator',
child: Icon(Icons.cached),
),
);
}
}