Restructure some things
This commit is contained in:
parent
99f15fda36
commit
d4bbca6405
9 changed files with 174 additions and 81 deletions
25
lib/Alert.dart
Normal file
25
lib/Alert.dart
Normal file
|
@ -0,0 +1,25 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class Alert extends StatelessWidget {
|
||||
String title;
|
||||
String body;
|
||||
Function()? dismissAction;
|
||||
|
||||
Alert(
|
||||
{required this.title, required this.body, super.key, this.dismissAction});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: Text(body),
|
||||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (dismissAction != null) dismissAction!.call();
|
||||
},
|
||||
child: Text("Dismiss"))
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,5 +2,5 @@ import 'package:flutter/material.dart';
|
|||
|
||||
class LibACFlutterConstants {
|
||||
static const Color TITLEBAR_COLOR = Color.fromARGB(255, 99, 0, 0);
|
||||
static const VERSION = "1.0.013125+1234";
|
||||
static const VERSION = "1.0.013125+1423";
|
||||
}
|
||||
|
|
|
@ -3,23 +3,35 @@ import 'package:flutter/material.dart';
|
|||
enum InputPromptType { Text, Number }
|
||||
|
||||
/// Prompt which enables the input of data
|
||||
///
|
||||
/// An input prompt can be for numbers or for text. Though the input type only affects platforms that display a keyboard.
|
||||
class InputPrompt extends StatefulWidget {
|
||||
String title;
|
||||
String prompt;
|
||||
String currentValue;
|
||||
InputPromptType type;
|
||||
Function()? cancelAction;
|
||||
Function(String)? successAction;
|
||||
|
||||
InputPrompt(
|
||||
{super.key,
|
||||
required this.title,
|
||||
required this.prompt,
|
||||
this.currentValue = "",
|
||||
required this.type});
|
||||
required this.type,
|
||||
this.cancelAction,
|
||||
this.successAction});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
// ignore: no_logic_in_create_state
|
||||
return InputPromptState(
|
||||
title: title, prompt: prompt, currentValue: currentValue, type: type);
|
||||
title: title,
|
||||
prompt: prompt,
|
||||
currentValue: currentValue,
|
||||
type: type,
|
||||
successAction: successAction ?? (str) {},
|
||||
cancelAction: cancelAction ?? () {});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,13 +40,17 @@ class InputPromptState extends State<InputPrompt> {
|
|||
String prompt;
|
||||
String currentValue;
|
||||
InputPromptType type;
|
||||
Function() cancelAction;
|
||||
Function(String) successAction;
|
||||
TextEditingController textField = TextEditingController();
|
||||
|
||||
InputPromptState(
|
||||
{required this.title,
|
||||
required this.prompt,
|
||||
required this.currentValue,
|
||||
required this.type}) {
|
||||
required this.type,
|
||||
required this.successAction,
|
||||
required this.cancelAction}) {
|
||||
textField.text = currentValue;
|
||||
}
|
||||
|
||||
|
@ -63,11 +79,13 @@ class InputPromptState extends State<InputPrompt> {
|
|||
actions: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
successAction.call(textField.text);
|
||||
Navigator.pop(context, textField.text);
|
||||
},
|
||||
child: Text("Submit")),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
cancelAction.call();
|
||||
Navigator.pop(context, "");
|
||||
},
|
||||
child: Text("Cancel"))
|
||||
|
@ -75,18 +93,3 @@ class InputPromptState extends State<InputPrompt> {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Alert extends StatelessWidget {
|
||||
String title;
|
||||
String body;
|
||||
|
||||
Alert({required this.title, required this.body, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
content: Text(body),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
31
lib/tests/alert.dart
Normal file
31
lib/tests/alert.dart
Normal file
|
@ -0,0 +1,31 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:libacflutter/Alert.dart';
|
||||
import 'package:libacflutter/Constants.dart';
|
||||
|
||||
class TestAlert extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Alert Dialog Null Callback Test"),
|
||||
backgroundColor: LibACFlutterConstants.TITLEBAR_COLOR),
|
||||
body: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (builder) {
|
||||
return Alert(
|
||||
title: "Test Alert",
|
||||
body: "This is a test that you can ignore");
|
||||
});
|
||||
|
||||
exit(0);
|
||||
},
|
||||
child: Text("Test Null Alert")),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
58
lib/tests/prompt.dart
Normal file
58
lib/tests/prompt.dart
Normal file
|
@ -0,0 +1,58 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:libacflutter/Alert.dart';
|
||||
import 'package:libacflutter/Constants.dart';
|
||||
import 'package:libacflutter/Prompt.dart';
|
||||
|
||||
class TestPrompt extends StatefulWidget {
|
||||
const TestPrompt({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return TestPromptState();
|
||||
}
|
||||
}
|
||||
|
||||
class TestPromptState extends State<TestPrompt> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Input Prompt Test"),
|
||||
backgroundColor: LibACFlutterConstants.TITLEBAR_COLOR,
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
var reply = await showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (buildx) {
|
||||
return InputPrompt(
|
||||
title: "Test",
|
||||
prompt: "Enter a value",
|
||||
currentValue: "",
|
||||
type: InputPromptType.Text,
|
||||
);
|
||||
});
|
||||
|
||||
// Show a alert dialog with the reply content
|
||||
showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (buildx) {
|
||||
return Alert(
|
||||
title: "Test Result",
|
||||
body: reply,
|
||||
dismissAction: () {
|
||||
exit(0);
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
child: Text("Show prompt"))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
21
lib/tests/tester.dart
Normal file
21
lib/tests/tester.dart
Normal file
|
@ -0,0 +1,21 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:libacflutter/tests/alert.dart';
|
||||
import 'package:libacflutter/tests/prompt.dart';
|
||||
|
||||
class WidgetTest extends StatelessWidget {
|
||||
String route;
|
||||
|
||||
WidgetTest({super.key, required this.route});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
theme: ThemeData.dark(),
|
||||
routes: {
|
||||
"/testprompt": (context) => TestPrompt(),
|
||||
"/testalert0": (context) => TestAlert()
|
||||
},
|
||||
home: TestPrompt(),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
name: libacflutter
|
||||
description: "A new Flutter package project."
|
||||
version: 1.0.013125+1234
|
||||
version: 1.0.013125+1423
|
||||
homepage: https://zontreck.com
|
||||
publish_to: https://git.zontreck.com/api/packages/AriasCreations/pub
|
||||
|
||||
|
|
11
test/testAlert.dart
Normal file
11
test/testAlert.dart
Normal file
|
@ -0,0 +1,11 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:libacflutter/tests/tester.dart';
|
||||
|
||||
void main() {
|
||||
test("Test a null alert callback", () async {
|
||||
runApp(WidgetTest(route: "/testalert0"));
|
||||
});
|
||||
}
|
|
@ -1,70 +1,14 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:libacflutter/Alert.dart';
|
||||
import 'package:libacflutter/Constants.dart';
|
||||
import 'package:libacflutter/Prompt.dart';
|
||||
import 'package:libacflutter/tests/tester.dart';
|
||||
|
||||
void main() {
|
||||
test("Test the input prompt", () async {
|
||||
runApp(WidgetTester(route: "/testprompt"));
|
||||
runApp(WidgetTest(route: "/testprompt"));
|
||||
});
|
||||
}
|
||||
|
||||
class WidgetTester extends StatelessWidget {
|
||||
String route;
|
||||
|
||||
WidgetTester({required this.route});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
theme: ThemeData.dark(),
|
||||
routes: {"/testprompt": (context) => TestPrompt()},
|
||||
home: TestPrompt(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TestPrompt extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return TestPromptState();
|
||||
}
|
||||
}
|
||||
|
||||
class TestPromptState extends State<TestPrompt> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Input Prompt Test"),
|
||||
backgroundColor: LibACFlutterConstants.TITLEBAR_COLOR,
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
var reply = await showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (buildx) {
|
||||
return InputPrompt(
|
||||
title: "Test",
|
||||
prompt: "Enter a value",
|
||||
currentValue: "",
|
||||
type: InputPromptType.Text,
|
||||
);
|
||||
});
|
||||
|
||||
// Show a alert dialog with the reply content
|
||||
showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (buildx) {
|
||||
return Alert(title: "Test Result", body: reply);
|
||||
});
|
||||
},
|
||||
child: Text("Show prompt"))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue