refact: init values from initState to Constractor (#8817)

* refact: init values from initState to Constractor

Signed-off-by: dignow <linlong1265@gmail.com>

* fix: move RxBool init into Constructor

Signed-off-by: dignow <linlong1265@gmail.com>

* peer sort option

Signed-off-by: dignow <linlong1265@gmail.com>

* Remove empty initState()

Signed-off-by: dignow <linlong1265@gmail.com>

---------

Signed-off-by: dignow <linlong1265@gmail.com>
This commit is contained in:
dignow
2024-07-25 10:45:51 +08:00
committed by GitHub
parent 2aef79688b
commit b967d496cc
24 changed files with 120 additions and 174 deletions

View File

@@ -35,11 +35,6 @@ class AddressBook extends StatefulWidget {
class _AddressBookState extends State<AddressBook> {
var menuPos = RelativeRect.fill;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) => Obx(() {
if (!gFFI.userModel.isLogin) {

View File

@@ -142,11 +142,6 @@ class _WidgetOPState extends State<WidgetOP> {
String _failedMsg = '';
String _url = '';
@override
void initState() {
super.initState();
}
@override
void dispose() {
super.dispose();

View File

@@ -23,11 +23,6 @@ class _MyGroupState extends State<MyGroup> {
RxString get searchUserText => gFFI.groupModel.searchUserText;
static TextEditingController searchUserController = TextEditingController();
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Obx(() {

View File

@@ -353,7 +353,7 @@ class Draggable extends StatefulWidget {
final Widget Function(BuildContext, GestureDragUpdateCallback) builder;
@override
State<StatefulWidget> createState() => _DraggableState();
State<StatefulWidget> createState() => _DraggableState(chatModel);
}
class _DraggableState extends State<Draggable> {
@@ -362,10 +362,8 @@ class _DraggableState extends State<Draggable> {
double _saveHeight = 0;
double _lastBottomHeight = 0;
@override
void initState() {
super.initState();
_chatModel = widget.chatModel;
_DraggableState(ChatModel? chatModel) {
_chatModel = chatModel;
}
get position => widget.position.pos;
@@ -467,7 +465,8 @@ class IOSDraggable extends StatefulWidget {
final Widget Function(BuildContext) builder;
@override
IOSDraggableState createState() => IOSDraggableState();
IOSDraggableState createState() =>
IOSDraggableState(chatModel, width, height);
}
class IOSDraggableState extends State<IOSDraggable> {
@@ -478,12 +477,10 @@ class IOSDraggableState extends State<IOSDraggable> {
double _saveHeight = 0;
double _lastBottomHeight = 0;
@override
void initState() {
super.initState();
_chatModel = widget.chatModel;
_width = widget.width;
_height = widget.height;
IOSDraggableState(ChatModel? chatModel, double w, double h) {
_chatModel = chatModel;
_width = w;
_height = h;
}
DraggableKeyPosition get position => widget.position;

View File

@@ -76,15 +76,11 @@ class _PeerTabPageState extends State<PeerTabPage>
final isOptVisiableFixed = isOptionFixed(kOptionPeerTabVisible);
@override
void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) {
_loadLocalOptions();
});
super.initState();
_PeerTabPageState() {
_loadLocalOptions();
}
Future<void> _loadLocalOptions() async {
void _loadLocalOptions() {
final uiType = bind.getLocalFlutterOption(k: kOptionPeerCardUiType);
if (uiType != '') {
peerCardUiType.value = int.parse(uiType) == 0
@@ -878,18 +874,13 @@ class PeerSortDropdown extends StatefulWidget {
}
class _PeerSortDropdownState extends State<PeerSortDropdown> {
@override
void initState() {
_PeerSortDropdownState() {
if (!PeerSortType.values.contains(peerSort.value)) {
// do not change obx directly in initState, so do in future.
WidgetsBinding.instance.addPostFrameCallback((_) {
_loadLocalOptions();
});
_loadLocalOptions();
}
super.initState();
}
Future<void> _loadLocalOptions() async {
void _loadLocalOptions() {
peerSort.value = PeerSortType.remoteId;
bind.setLocalFlutterOption(
k: kOptionPeerSorting,

View File

@@ -45,10 +45,14 @@ class LoadEvent {
final peerSearchText = "".obs;
/// for peer sort, global obs value
final peerSort = bind.getLocalFlutterOption(k: kOptionPeerSorting).obs;
RxString? _peerSort;
RxString get peerSort {
_peerSort ??= bind.getLocalFlutterOption(k: kOptionPeerSorting).obs;
return _peerSort!;
}
// list for listener
final obslist = [peerSearchText, peerSort].obs;
RxList<RxString> get obslist => [peerSearchText, peerSort].obs;
final peerSearchTextController =
TextEditingController(text: peerSearchText.value);