Skip to content
This repository has been archived by the owner on Jan 31, 2021. It is now read-only.

Commit

Permalink
Text Box Enahancements (#44)
Browse files Browse the repository at this point in the history
* Text Box Enahancements

* Apply suggestions from code review

fixed spelling error

* fix error when pressing clear button

* fixed rendering error

* get rid of setState

Co-authored-by: Gogs <gogs@fake.local>
Co-authored-by: David <davidmccoy@mailfence.com>
  • Loading branch information
3 people authored Apr 17, 2020
1 parent 1f61b98 commit 8995961
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
36 changes: 21 additions & 15 deletions flutter_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class _MyHomePageState extends State<MyHomePage> {
bool isAttemptingToJoinSessionFromText = false;
bool isAttemptingToJoinSessionFromQR = false;
SidMessage sidMessage;
TextEditingController _controller = TextEditingController();
TextEditingController _messageController = TextEditingController();
TextEditingController _urlTextController = TextEditingController();
Timer serverTimeTimer;
Timer pingTimer;
String _username;
Expand Down Expand Up @@ -200,6 +199,10 @@ class _MyHomePageState extends State<MyHomePage> {
sendMessage(new BufferingMessage(bufferingContent));
}

void _onSubmitPressedInUrlField(String s) {
_onConnectPressed();
}

void _onConnectPressed() {
setState(() {
isAttemptingToJoinSessionFromText = true;
Expand All @@ -211,31 +214,31 @@ class _MyHomePageState extends State<MyHomePage> {
sessionJoined = false;
sessionId = "";
String serverId = "";
int varStart = _controller.text.toString().indexOf('?');
int varStart = _urlTextController.text.toString().indexOf('?');
if (varStart >= 0) {
int sessionIdStart = _controller.text.toString().indexOf(
int sessionIdStart = _urlTextController.text.toString().indexOf(
'npSessionId=');
if (sessionIdStart >= 0) {
int sessionIdEnd = _controller.text.toString().indexOf(
int sessionIdEnd = _urlTextController.text.toString().indexOf(
'&', sessionIdStart);
if (sessionIdEnd > sessionIdStart) {
sessionId = _controller.text.toString().substring(
sessionId = _urlTextController.text.toString().substring(
sessionIdStart + 12, sessionIdEnd);
} else {
sessionId =
_controller.text.toString().substring(sessionIdStart + 12);
_urlTextController.text.toString().substring(sessionIdStart + 12);
}
}
int serverIdStart = _controller.text.toString().indexOf('npServerId=');
int serverIdStart = _urlTextController.text.toString().indexOf('npServerId=');
if (serverIdStart >= 0) {
int serverIdEnd = _controller.text.toString().indexOf(
int serverIdEnd = _urlTextController.text.toString().indexOf(
'&', serverIdStart);
if (serverIdEnd > serverIdStart) {
serverId = _controller.text.toString().substring(
serverId = _urlTextController.text.toString().substring(
serverIdStart + 11, serverIdEnd);
} else {
serverId =
_controller.text.toString().substring(serverIdStart + 11);
_urlTextController.text.toString().substring(serverIdStart + 11);
}
}
}
Expand Down Expand Up @@ -412,8 +415,12 @@ class _MyHomePageState extends State<MyHomePage> {
List<Widget> getNotConnectedWidgets() {
List<Widget> widgets = new List<Widget>();
widgets.add(TextFormField(
controller: _controller,
decoration: InputDecoration(labelText: 'Enter URL'),
textInputAction: TextInputAction.go,
onFieldSubmitted: _onSubmitPressedInUrlField,
controller: _urlTextController,
decoration: InputDecoration(labelText: 'Enter URL', suffixIcon: IconButton(icon: Icon(Icons.cancel), onPressed: () {
WidgetsBinding.instance.addPostFrameCallback( (_) => _urlTextController.clear());
},)),
));
widgets.add(Padding(
padding: new EdgeInsets.fromLTRB(50, 10, 50, 10),
Expand Down Expand Up @@ -445,7 +452,7 @@ class _MyHomePageState extends State<MyHomePage> {
void _onScanQRPressed() async {
debugPrint('qr pressed');
var result = await BarcodeScanner.scan();
_controller.text = result;
_urlTextController.text = result;
_connectToServer();
setState(() {
isAttemptingToJoinSessionFromQR = true;
Expand Down Expand Up @@ -507,4 +514,3 @@ class _MyHomePageState extends State<MyHomePage> {
}
}


4 changes: 3 additions & 1 deletion flutter_app/lib/pages/UserSettingsScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ class _UserSettingsScreenState extends State<UserSettingsScreen> {
padding: const EdgeInsets.all(20.0),
child: Column( children: [new TextFormField(
controller: _usernameController,
decoration: InputDecoration(labelText: 'Enter Username'),
decoration: InputDecoration(labelText: 'Enter Username', suffixIcon: IconButton(icon: Icon(Icons.cancel), onPressed: () {
WidgetsBinding.instance.addPostFrameCallback( (_) => _usernameController.clear());
},)),
), Expanded( child: GridView.count(crossAxisCount: 4,
crossAxisSpacing: 4.0,
mainAxisSpacing: 8.0,
Expand Down

0 comments on commit 8995961

Please sign in to comment.