@@ -11,11 +11,11 @@ class RegisterWidget extends StatefulWidget {
1111
1212class _MyRegisterWidget extends State <RegisterWidget >
1313 implements SipUaHelperListener {
14- String _password ;
15- String _wsUri ;
16- String _sipUri ;
17- String _displayName ;
18- String _authorizationUser ;
14+ TextEditingController _passwordController = TextEditingController () ;
15+ TextEditingController _wsUriController = TextEditingController () ;
16+ TextEditingController _sipUriController = TextEditingController () ;
17+ TextEditingController _displayNameController = TextEditingController () ;
18+ TextEditingController _authorizationUserController = TextEditingController () ;
1919 Map <String , String > _wsExtraHeaders = {
2020 'Origin' : ' https://tryit.jssip.net' ,
2121 'Host' : 'tryit.jssip.net:10443'
@@ -43,22 +43,22 @@ class _MyRegisterWidget extends State<RegisterWidget>
4343 void _loadSettings () async {
4444 _preferences = await SharedPreferences .getInstance ();
4545 this .setState (() {
46- _wsUri =
46+ _wsUriController.text =
4747 _preferences.getString ('ws_uri' ) ?? 'wss://tryit.jssip.net:10443' ;
48- _sipUri =
48+ _sipUriController.text =
4949 _preferences.
getString (
'sip_uri' )
?? '[email protected] ' ;
50- _displayName = _preferences.getString ('display_name' ) ?? 'Flutter SIP UA' ;
51- _password = _preferences.getString ('password' );
52- _authorizationUser = _preferences.getString ('auth_user' );
50+ _displayNameController.text = _preferences.getString ('display_name' ) ?? 'Flutter SIP UA' ;
51+ _passwordController.text = _preferences.getString ('password' );
52+ _authorizationUserController.text = _preferences.getString ('auth_user' );
5353 });
5454 }
5555
5656 void _saveSettings () {
57- _preferences.setString ('ws_uri' , _wsUri );
58- _preferences.setString ('sip_uri' , _sipUri );
59- _preferences.setString ('display_name' , _displayName );
60- _preferences.setString ('password' , _password );
61- _preferences.setString ('auth_user' , _authorizationUser );
57+ _preferences.setString ('ws_uri' , _wsUriController.text );
58+ _preferences.setString ('sip_uri' , _sipUriController.text );
59+ _preferences.setString ('display_name' , _displayNameController.text );
60+ _preferences.setString ('password' , _passwordController.text );
61+ _preferences.setString ('auth_user' , _authorizationUserController.text );
6262 }
6363
6464 @override
@@ -90,23 +90,23 @@ class _MyRegisterWidget extends State<RegisterWidget>
9090 }
9191
9292 void _handleSave (BuildContext context) {
93- if (_wsUri == null ) {
93+ if (_wsUriController.text == null ) {
9494 _alert (context, "WebSocket URL" );
95- } else if (_sipUri == null ) {
95+ } else if (_sipUriController.text == null ) {
9696 _alert (context, "SIP URI" );
9797 }
9898
9999 UaSettings settings = UaSettings ();
100100
101- settings.webSocketUrl = _wsUri ;
101+ settings.webSocketUrl = _wsUriController.text ;
102102 settings.webSocketSettings.extraHeaders = _wsExtraHeaders;
103103 settings.webSocketSettings.allowBadCertificate = true ;
104104 settings.webSocketSettings.userAgent = 'Dart/2.8 (dart:io) for OpenSIPS.' ;
105105
106- settings.uri = _sipUri ;
107- settings.authorizationUser = _authorizationUser ;
108- settings.password = _password ;
109- settings.displayName = _displayName ;
106+ settings.uri = _sipUriController.text ;
107+ settings.authorizationUser = _authorizationUserController.text ;
108+ settings.password = _passwordController.text ;
109+ settings.displayName = _displayNameController.text ;
110110 settings.userAgent = 'Dart SIP Client v1.0.0' ;
111111 settings.dtmfMode = DtmfMode .RFC2833 ;
112112
@@ -145,20 +145,15 @@ class _MyRegisterWidget extends State<RegisterWidget>
145145 ),
146146 Padding (
147147 padding: const EdgeInsets .fromLTRB (48.0 , 0.0 , 48.0 , 0 ),
148- child: TextField (
148+ child: TextFormField (
149+ controller: _wsUriController,
149150 keyboardType: TextInputType .text,
150151 textAlign: TextAlign .center,
151152 decoration: InputDecoration (
152153 contentPadding: EdgeInsets .all (10.0 ),
153154 border: UnderlineInputBorder (
154155 borderSide: BorderSide (color: Colors .black12)),
155- hintText: _wsUri,
156156 ),
157- onChanged: (value) {
158- setState (() {
159- _wsUri = value;
160- });
161- },
162157 ),
163158 ),
164159 ],
@@ -174,20 +169,15 @@ class _MyRegisterWidget extends State<RegisterWidget>
174169 ),
175170 Padding (
176171 padding: const EdgeInsets .fromLTRB (48.0 , 0.0 , 48.0 , 0 ),
177- child: TextField (
172+ child: TextFormField (
173+ controller: _sipUriController,
178174 keyboardType: TextInputType .text,
179175 textAlign: TextAlign .center,
180176 decoration: InputDecoration (
181177 contentPadding: EdgeInsets .all (10.0 ),
182178 border: UnderlineInputBorder (
183179 borderSide: BorderSide (color: Colors .black12)),
184- hintText: _sipUri,
185180 ),
186- onChanged: (value) {
187- setState (() {
188- _sipUri = value;
189- });
190- },
191181 ),
192182 ),
193183 ],
@@ -203,20 +193,16 @@ class _MyRegisterWidget extends State<RegisterWidget>
203193 ),
204194 Padding (
205195 padding: const EdgeInsets .fromLTRB (48.0 , 0.0 , 48.0 , 0 ),
206- child: TextField (
196+ child: TextFormField (
197+ controller: _authorizationUserController,
207198 keyboardType: TextInputType .text,
208199 textAlign: TextAlign .center,
209200 decoration: InputDecoration (
210201 contentPadding: EdgeInsets .all (10.0 ),
211202 border: UnderlineInputBorder (
212203 borderSide: BorderSide (color: Colors .black12)),
213- hintText: _authorizationUser ?? '[Empty]' ,
204+ hintText: _authorizationUserController.text ? .isEmpty ?? true ? '[Empty]' : null ,
214205 ),
215- onChanged: (value) {
216- setState (() {
217- _authorizationUser = value;
218- });
219- },
220206 ),
221207 ),
222208 ],
@@ -232,20 +218,16 @@ class _MyRegisterWidget extends State<RegisterWidget>
232218 ),
233219 Padding (
234220 padding: const EdgeInsets .fromLTRB (48.0 , 0.0 , 48.0 , 0 ),
235- child: TextField (
221+ child: TextFormField (
222+ controller: _passwordController,
236223 keyboardType: TextInputType .text,
237224 textAlign: TextAlign .center,
238225 decoration: InputDecoration (
239226 contentPadding: EdgeInsets .all (10.0 ),
240227 border: UnderlineInputBorder (
241228 borderSide: BorderSide (color: Colors .black12)),
242- hintText: _password ?? '[Empty]' ,
229+ hintText: _passwordController.text ? .isEmpty ?? true ? '[Empty]' : null ,
243230 ),
244- onChanged: (value) {
245- setState (() {
246- _password = value;
247- });
248- },
249231 ),
250232 ),
251233 ],
@@ -261,20 +243,15 @@ class _MyRegisterWidget extends State<RegisterWidget>
261243 ),
262244 Padding (
263245 padding: const EdgeInsets .fromLTRB (48.0 , 0.0 , 48.0 , 0 ),
264- child: TextField (
246+ child: TextFormField (
247+ controller: _displayNameController,
265248 keyboardType: TextInputType .text,
266249 textAlign: TextAlign .center,
267250 decoration: InputDecoration (
268251 contentPadding: EdgeInsets .all (10.0 ),
269252 border: UnderlineInputBorder (
270253 borderSide: BorderSide (color: Colors .black12)),
271- hintText: _displayName,
272254 ),
273- onChanged: (value) {
274- setState (() {
275- _displayName = value;
276- });
277- },
278255 ),
279256 ),
280257 ],
0 commit comments