setNetwork.dart
3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import 'package:flutter/material.dart';
import 'package:flutter_mes2/utils/ToastUtil.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'https/dio_utils.dart';
import 'utils/Constant.dart';
class setNetwork extends StatefulWidget {
@override
State<StatefulWidget> createState() => StateFulWidgetDemo1State();
}
class StateFulWidgetDemo1State extends State<setNetwork> {
//手机号的控制器
TextEditingController networkController = TextEditingController();
var network;
save() async{
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString(Constant.NETWORK, network);
}
get() async{
SharedPreferences prefs = await SharedPreferences.getInstance();
network = prefs.getString(Constant.NETWORK);
setState(() {
});
}
@override
void initState() {
// TODO: implement initState
super.initState();
get();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('设置网络'),
centerTitle: true, // 标题居中
),
body:
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
margin: EdgeInsets.only(left:30, right: 30, bottom: 10),
child:
Text("网络地址:$network",style:TextStyle(fontSize: 16)),
),
Container(
margin: EdgeInsets.only(left:30, right: 30, bottom: 10),
child:
TextField(
controller: networkController,
decoration: InputDecoration(
border: OutlineInputBorder(),
contentPadding: EdgeInsets.all(10.0),
),),
),
Container(
height: 40,
margin: EdgeInsets.only(left:30, right: 30, bottom: 10, top: 10),
width: double.infinity,
child: RaisedButton(
onPressed: () {
network = Constant.DEFAULT_NETWORK;
networkController.text = Constant.DEFAULT_NETWORK;
},
child: Text('默认地址',
style: TextStyle(
fontSize: 20,
color: Colors.white
),),
color: Colors.deepOrangeAccent,
textColor: Colors.white,
shape: StadiumBorder(),
),
),
Container(
height: 40,
margin: EdgeInsets.only(left:30, right: 30, bottom: 10, top: 10),
width: double.infinity,
child: RaisedButton(
onPressed:() {
setState(() {
ToastUtil.showText( "设置成功");
network = networkController.value.text.toString();
save();
DioUtils.network = network;
});
},
child: Text('设置',
style: TextStyle(
fontSize: 20,
color: Colors.white
),),
color: Colors.deepOrangeAccent,
textColor: Colors.white,
shape: StadiumBorder(),
),
),
],
),
),
);
}
}