Apply Flutter best practices [Non-Breaking] (#2)
* Add flutter_lints package * Use key in widget constructors lint: use_key_in_widget_constructors * Unnecessary new keyword lint: unnecessary_new * Prefer const with constant constructors * Exclude protobuf files from analyzer * Private field could be final * Annotate overridden members * Use initializing formals when possible * Don't access members with `this` unless avoiding shadowing * Prefer is! operator * Use isEmpty instead of length * Use collection literals when possible * Revert comment changes * Cleaner null testing * Misc fixes * Avoid using `forEach` with a function literal * Prefer `final` over `var` where applicable * Enforce stricter type-checking * Ignore VS Code files * Flutter format * Prefer using lowerCamelCase for constant names * flutter format -l 100 * Disable `avoid_print` for examples * Slight improvements to example Should solve lint error: no_logic_in_create_state
This commit is contained in:
+83
-58
@@ -10,88 +10,113 @@ void main() {
|
||||
print('${record.level.name}: ${record.time}: ${record.message}');
|
||||
});
|
||||
|
||||
runApp(MyApp());
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
// This widget is the root of your application.
|
||||
//
|
||||
const MyApp({
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'LiveKit Demo',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.deepPurple,
|
||||
),
|
||||
home: PreConnect(),
|
||||
);
|
||||
}
|
||||
Widget build(BuildContext context) => MaterialApp(
|
||||
title: 'LiveKit Demo',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.deepPurple,
|
||||
),
|
||||
home: const PreConnectWidget(
|
||||
url: '<livekit_host>',
|
||||
token: '<access_token>',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class PreConnect extends StatefulWidget {
|
||||
class PreConnectWidget extends StatefulWidget {
|
||||
//
|
||||
final String url;
|
||||
final String token;
|
||||
|
||||
const PreConnectWidget({
|
||||
required this.url,
|
||||
required this.token,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _PreConnectState(
|
||||
'<livekit_host>',
|
||||
'<access_token>',
|
||||
);
|
||||
}
|
||||
State<StatefulWidget> createState() => _PreConnectWidgetState();
|
||||
}
|
||||
|
||||
class _PreConnectState extends State<PreConnect> {
|
||||
String url;
|
||||
String token;
|
||||
class _PreConnectWidgetState extends State<PreConnectWidget> {
|
||||
//
|
||||
final _urlCtrl = TextEditingController();
|
||||
final _tokenCtrl = TextEditingController();
|
||||
|
||||
_PreConnectState(this.url, this.token);
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_urlCtrl.text = widget.url;
|
||||
_tokenCtrl.text = widget.token;
|
||||
}
|
||||
|
||||
_connect(BuildContext context) async {
|
||||
@override
|
||||
void dispose() {
|
||||
_urlCtrl.dispose();
|
||||
_tokenCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _connect(BuildContext context) async {
|
||||
try {
|
||||
var room = await LiveKitClient.connect(this.url, this.token);
|
||||
Navigator.push(
|
||||
print('Connecting with url: ${_urlCtrl.text}, token: ${_tokenCtrl.text}...');
|
||||
|
||||
final room = await LiveKitClient.connect(
|
||||
_urlCtrl.text,
|
||||
_tokenCtrl.text,
|
||||
);
|
||||
|
||||
Navigator.push<void>(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) {
|
||||
return RoomWidget(room);
|
||||
}),
|
||||
);
|
||||
} catch (e) {
|
||||
print("could not connect $e");
|
||||
print('could not connect $e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Connect to LiveKit'),
|
||||
),
|
||||
body: Center(
|
||||
child: Container(
|
||||
// width: 250,
|
||||
alignment: Alignment.center,
|
||||
margin: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'URL',
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Connect to LiveKit'),
|
||||
),
|
||||
body: Center(
|
||||
child: Container(
|
||||
// width: 250,
|
||||
alignment: Alignment.center,
|
||||
margin: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
TextField(
|
||||
controller: _urlCtrl,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'URL',
|
||||
),
|
||||
),
|
||||
onChanged: (value) => this.url,
|
||||
initialValue: this.url,
|
||||
),
|
||||
TextFormField(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Token',
|
||||
TextField(
|
||||
controller: _tokenCtrl,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Token',
|
||||
),
|
||||
),
|
||||
onChanged: (value) => this.token,
|
||||
initialValue: this.token,
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => _connect(context),
|
||||
child: Text('Connect'),
|
||||
),
|
||||
],
|
||||
TextButton(
|
||||
onPressed: () => _connect(context),
|
||||
child: const Text('Connect'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user