Improve efficiency of data fetching
This commit is contained in:
@@ -65,6 +65,7 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
super.didChangeAppLifecycleState(state);
|
||||
if (state == AppLifecycleState.paused) {
|
||||
_serverProvider.setDisconnected();
|
||||
_serverProvider.stopAutoRefresh();
|
||||
}
|
||||
if (state == AppLifecycleState.resumed) {
|
||||
@@ -90,9 +91,11 @@ class _MyHomePageState extends State<MyHomePage>
|
||||
),
|
||||
),
|
||||
drawer: _buildDrawer(),
|
||||
body: TabBarView(
|
||||
controller: _tabController,
|
||||
children: const [ServerPage(), ConvertPage(), PingPage()]),
|
||||
body: TabBarView(controller: _tabController, children: [
|
||||
ServerPage(_tabController),
|
||||
const ConvertPage(),
|
||||
const PingPage()
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ class _PingPageState extends State<PingPage>
|
||||
buildInput(context, _textEditingController,
|
||||
maxLines: 1, hint: 'Type here.'),
|
||||
_buildControl(),
|
||||
buildInput(context, _textEditingControllerResult, hint: 'Result here.'),
|
||||
buildInput(context, _textEditingControllerResult,
|
||||
hint: 'Result here.'),
|
||||
])),
|
||||
onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
|
||||
),
|
||||
@@ -73,46 +74,46 @@ class _PingPageState extends State<PingPage>
|
||||
child: InkWell(
|
||||
onTap: () => FocusScope.of(context).unfocus(),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
TextButton(
|
||||
style: ButtonStyle(
|
||||
foregroundColor: MaterialStateProperty.all(primaryColor)),
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.stop),
|
||||
SizedBox(
|
||||
width: 7,
|
||||
),
|
||||
Text('Stop')
|
||||
],
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
TextButton(
|
||||
style: ButtonStyle(
|
||||
foregroundColor: MaterialStateProperty.all(primaryColor)),
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.stop),
|
||||
SizedBox(
|
||||
width: 7,
|
||||
),
|
||||
Text('Stop')
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
if (_ping != null) _ping!.stop();
|
||||
},
|
||||
),
|
||||
onPressed: () {
|
||||
if (_ping != null) _ping!.stop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
style: ButtonStyle(
|
||||
foregroundColor: MaterialStateProperty.all(primaryColor)),
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.play_arrow),
|
||||
SizedBox(
|
||||
width: 7,
|
||||
),
|
||||
Text('Start')
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
try {
|
||||
doPing();
|
||||
} catch (e) {
|
||||
showSnackBar(context, Text('Error: \n$e'));
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
TextButton(
|
||||
style: ButtonStyle(
|
||||
foregroundColor: MaterialStateProperty.all(primaryColor)),
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.play_arrow),
|
||||
SizedBox(
|
||||
width: 7,
|
||||
),
|
||||
Text('Start')
|
||||
],
|
||||
),
|
||||
onPressed: () {
|
||||
try {
|
||||
doPing();
|
||||
} catch (e) {
|
||||
showSnackBar(context, Text('Error: \n$e'));
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -17,7 +17,8 @@ import 'package:toolbox/view/page/server/detail.dart';
|
||||
import 'package:toolbox/view/page/server/edit.dart';
|
||||
|
||||
class ServerPage extends StatefulWidget {
|
||||
const ServerPage({Key? key}) : super(key: key);
|
||||
final TabController tabController;
|
||||
const ServerPage(this.tabController, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ServerPageState createState() => _ServerPageState();
|
||||
@@ -45,6 +46,9 @@ class _ServerPageState extends State<ServerPage>
|
||||
_media = MediaQuery.of(context);
|
||||
_theme = Theme.of(context);
|
||||
_primaryColor = primaryColor;
|
||||
if (widget.tabController.index == 0) {
|
||||
FocusScope.of(context).unfocus();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -194,7 +194,6 @@ class _SettingPageState extends State<SettingPage> {
|
||||
child: Text(
|
||||
tabs[_launchPageIdx],
|
||||
style: textStyle,
|
||||
textScaleFactor: 1.0,
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user