Skip to content

Commit

Permalink
Added Textfield validation
Browse files Browse the repository at this point in the history
Validated if Textfield was numeric or not and if it was empty
  • Loading branch information
martin-headspace committed Feb 17, 2020
1 parent b28db71 commit 490ef90
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 41 deletions.
8 changes: 8 additions & 0 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 56 additions & 40 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 40 additions & 1 deletion eight_queens/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:eight_queens/queens.dart';
import 'package:eight_queens/results.dart';
import 'package:flutter/material.dart';
import 'package:progress_dialog/progress_dialog.dart';

import 'package:validators/validators.dart';

void main() => runApp(MyApp());

Expand Down Expand Up @@ -40,6 +40,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
int _boardSize = 0;
ProgressDialog pr;
bool shouldCheck;

// Create a controller to retrieve data from the TextField
final boardController = TextEditingController();
Expand All @@ -51,11 +52,49 @@ class _MyHomePageState extends State<MyHomePage> {
super.dispose();
}

void _showDialogBuilder(String title, String message) {
showDialog(context: context,builder: (BuildContext context){
return AlertDialog(
title: new Text(title),
content: new Text(message),
actions: <Widget>[
new FlatButton(
child: new Text("close"), onPressed: () {
setState(() {
_boardSize = 0;
});
Navigator.of(context).pop();
})
],
);
});
}

@override
void initState() {
// TODO: implement initState
setState(() {
shouldCheck = true;
});
super.initState();
}

/**
* Retrieve the board number and pass it to the eight queens controller
* TODO: Create the Responsible class in Dart
*/
void _startProcessing() async {

if(boardController.text.isEmpty){
_showDialogBuilder("Empty Textfield", "Please enter a value into the text field");
return;
}

if(boardController.text.isNotEmpty && !isNumeric(boardController.text)) {
_showDialogBuilder("Non numeric", "Please enter a numeric value into the text field");
return;
}

setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
Expand Down
1 change: 1 addition & 0 deletions eight_queens/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
flutter:
sdk: flutter
shared_preferences : ^0.5.6
validators: ^2.0.0

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand Down

0 comments on commit 490ef90

Please sign in to comment.