Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integration and differenciation #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions math_keyboard/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,73 @@
## UPCOMING RELEASE

- keyboard now supports both integration and derivation

## 0.3.0

* Updated all dependencies
* Require flutter: `'>=3.22.2'`
- Updated all dependencies
- Require flutter: `'>=3.22.2'`

## 0.2.1

* Added Android support to the demo project.
* Closes keyboard on Android hardware back button press.
- Added Android support to the demo project.
- Closes keyboard on Android hardware back button press.

## 0.2.0

* Bumped `flutter_math_fork` and `intl`.
- Bumped `flutter_math_fork` and `intl`.

## 0.1.9

* Exposes `MathKeyboards` and adds padding and hover effects to it.
- Exposes `MathKeyboards` and adds padding and hover effects to it.

## 0.1.8

* Return empty string instead of \\Box when field is empty
- Return empty string instead of \\Box when field is empty

## 0.1.7

* Updated Petitparser dependency.
- Updated Petitparser dependency.

## 0.1.6

* Cleared Flutter 3.0.x warnings.
- Cleared Flutter 3.0.x warnings.

## 0.1.5

* Updated field cursor using `\cursor` function from `flutter_math_fork 0.6.2`.
- Updated field cursor using `\cursor` function from `flutter_math_fork 0.6.2`.

## 0.1.4+1

* Bumped `flutter_math_fork`.
- Bumped `flutter_math_fork`.

## 0.1.4

* Fixed missing implicit times operator between a closing and an opening parenthesis.
- Fixed missing implicit times operator between a closing and an opening parenthesis.

## 0.1.3

* Added new symbols icon for functions button.
* Added fraction button to second keyboard page.
- Added new symbols icon for functions button.
- Added fraction button to second keyboard page.

## 0.1.2

* Bumped `flutter_math_fork`.
- Bumped `flutter_math_fork`.

## 0.1.1+1

* Fixed `numpadBackspace` breaking change.
* Addressed `ThemeData.accentColor` deprecations.
- Fixed `numpadBackspace` breaking change.
- Addressed `ThemeData.accentColor` deprecations.

## 0.1.1

* Unary minus support when converting to an expression.
* Keep parentheses when initialising controller with an expression.
* Added special cases for pi and e when initializing controller.
- Unary minus support when converting to an expression.
- Keep parentheses when initialising controller with an expression.
- Added special cases for pi and e when initializing controller.

## 0.1.0+1

* Fixed styling of commas as decimal separators.
- Fixed styling of commas as decimal separators.

## 0.1.0

* Initial public version.
- Initial public version.
14 changes: 14 additions & 0 deletions math_keyboard/lib/src/foundation/keyboard_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,20 @@ final functionKeyboard = [
asTex: true,
),
],
[
const BasicKeyboardButtonConfig(
label: r'\int_{\Box}^{\Box} (\Box) dx',
value: r'\int',
asTex: true,
args: [TeXArg.undbraces, TeXArg.powbraces, TeXArg.parenthesesdx],
),
const BasicKeyboardButtonConfig(
label: r'\frac{d}{dx} ({\Box})',
value: r'\frac{d}{dx}',
asTex: true,
args: [TeXArg.braces],
),
],
[
const PageButtonConfig(flex: 3),
const BasicKeyboardButtonConfig(
Expand Down
25 changes: 25 additions & 0 deletions math_keyboard/lib/src/foundation/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ class TeXFunction extends TeX {
switch (type) {
case TeXArg.braces:
return '{';
case TeXArg.powbraces:
return '^{';
case TeXArg.undbraces:
return '_{';
case TeXArg.brackets:
return '[';
default:
Expand All @@ -161,8 +165,14 @@ class TeXFunction extends TeX {
switch (type) {
case TeXArg.braces:
return '}';
case TeXArg.powbraces:
return '}';
case TeXArg.undbraces:
return '}';
case TeXArg.brackets:
return ']';
case TeXArg.parenthesesdx:
return r') dx';
default:
return ')';
}
Expand Down Expand Up @@ -233,6 +243,16 @@ enum NavigationState {

/// How the argument is marked.
enum TeXArg {
/// _{ }
///
/// In most of the cases, braces will be used. (E.g arguments of fractions).
undbraces,

/// ^{ }
///
/// In most of the cases, braces will be used. (E.g arguments of fractions).
powbraces,

/// { }
///
/// In most of the cases, braces will be used. (E.g arguments of fractions).
Expand All @@ -249,4 +269,9 @@ enum TeXArg {
/// for functions like sin, cos, tan, etc. as well, so the user doesn't have
/// to close the parentheses manually.
parentheses,

/// ()
///
/// A completely custom end just to make integration work properly
parenthesesdx,
}
12 changes: 12 additions & 0 deletions math_keyboard/lib/src/widgets/math_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ class _FieldPreview extends StatelessWidget {
'{${decimalSeparator(context)}}',
);

print(tex);
return ConstrainedBox(
constraints: const BoxConstraints(
minWidth: double.infinity,
Expand Down Expand Up @@ -825,6 +826,8 @@ class MathFieldEditingController extends ChangeNotifier {
// The same applies for fractions.
else if (tex == r'\frac') {
addFrac(func);
} else if (tex == r'\int') {
addInt(func);
} else {
currentNode.addTeX(func);
currentNode = func.argNodes.first;
Expand All @@ -833,6 +836,15 @@ class MathFieldEditingController extends ChangeNotifier {
notifyListeners();
}

/// Adds an integration to the current node
///
void addInt(TeXFunction int) {
// were adding dx to the end of the integration function

currentNode.addTeX(int);
currentNode = int.argNodes.first;
}

/// Adds a pow to the current node
///
/// If the expression is ^2 instead of ^, we want to set 2 as the argument
Expand Down
2 changes: 1 addition & 1 deletion math_keyboard/lib/src/widgets/math_keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class _Buttons extends StatelessWidget {
@override
Widget build(BuildContext context) {
return SizedBox(
height: 230,
height: 280,
child: AnimatedBuilder(
animation: controller,
builder: (context, child) {
Expand Down
31 changes: 19 additions & 12 deletions math_keyboard_demo/lib/widgets/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@ class _DemoAppState extends State<DemoApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: appTitle,
theme: ThemeData(
brightness: _darkMode ? Brightness.dark : Brightness.light,
),
home: DemoScaffold(
onToggleBrightness: () {
setState(() {
_darkMode = !_darkMode;
});
},
),
);
title: appTitle,
theme: ThemeData(
brightness: _darkMode ? Brightness.dark : Brightness.light,
),
home: MyTest());
}
}

class MyTest extends StatefulWidget {
const MyTest({super.key});

@override
State<MyTest> createState() => _MyTestState();
}

class _MyTestState extends State<MyTest> {
@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
Loading