mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: sync name on change (AppFlowy-IO#2033) (#2065)
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/startup/startup.dart';
|
import 'package:appflowy/startup/startup.dart';
|
||||||
@ -63,17 +64,34 @@ class SettingsUserView extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
class UserNameInput extends StatelessWidget {
|
class UserNameInput extends StatefulWidget {
|
||||||
final String name;
|
final String name;
|
||||||
|
|
||||||
const UserNameInput(
|
const UserNameInput(
|
||||||
this.name, {
|
this.name, {
|
||||||
Key? key,
|
Key? key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
UserNameInputState createState() => UserNameInputState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class UserNameInputState extends State<UserNameInput> {
|
||||||
|
late TextEditingController _controller;
|
||||||
|
|
||||||
|
Timer? _debounce;
|
||||||
|
final Duration _debounceDuration = const Duration(milliseconds: 500);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_controller = TextEditingController(text: widget.name);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return TextField(
|
return TextField(
|
||||||
controller: TextEditingController()..text = name,
|
controller: _controller,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: LocaleKeys.settings_user_name.tr(),
|
labelText: LocaleKeys.settings_user_name.tr(),
|
||||||
labelStyle: Theme.of(context)
|
labelStyle: Theme.of(context)
|
||||||
@ -88,13 +106,25 @@ class UserNameInput extends StatelessWidget {
|
|||||||
borderSide: BorderSide(color: Theme.of(context).colorScheme.primary),
|
borderSide: BorderSide(color: Theme.of(context).colorScheme.primary),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onSubmitted: (val) {
|
onChanged: (val) {
|
||||||
|
if (_debounce?.isActive ?? false) {
|
||||||
|
_debounce!.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
_debounce = Timer(_debounceDuration, () {
|
||||||
context
|
context
|
||||||
.read<SettingsUserViewBloc>()
|
.read<SettingsUserViewBloc>()
|
||||||
.add(SettingsUserEvent.updateUserName(val));
|
.add(SettingsUserEvent.updateUserName(val));
|
||||||
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _OpenaiKeyInput extends StatefulWidget {
|
class _OpenaiKeyInput extends StatefulWidget {
|
||||||
|
Reference in New Issue
Block a user