From dcf0bd76bbfd52b54770e6882403963461eac80a Mon Sep 17 00:00:00 2001 From: DXie123 <1541278149@qq.com> Date: Thu, 14 Nov 2019 20:06:06 +0800 Subject: [PATCH] reorganize project structure --- lib/main.dart | 11 ++-- lib/src/{ => backend}/function.dart | 0 lib/src/{ => backend}/latex.dart | 2 +- lib/src/{ => backend}/mathmodel.dart | 2 +- lib/src/{ => pages}/settingpage.dart | 2 +- .../{mybutton.dart => widgets/keyboard.dart} | 6 +- lib/src/{ => widgets}/mathbox.dart | 2 +- .../matrixbutton.dart} | 58 +------------------ lib/src/widgets/result.dart | 58 +++++++++++++++++++ test/latex_parser_test.dart | 3 +- test/matrix_test.dart | 3 +- 11 files changed, 77 insertions(+), 70 deletions(-) rename lib/src/{ => backend}/function.dart (100%) rename lib/src/{ => backend}/latex.dart (99%) rename lib/src/{ => backend}/mathmodel.dart (98%) rename lib/src/{ => pages}/settingpage.dart (98%) rename lib/src/{mybutton.dart => widgets/keyboard.dart} (98%) rename lib/src/{ => widgets}/mathbox.dart (99%) rename lib/src/{result.dart => widgets/matrixbutton.dart} (67%) create mode 100644 lib/src/widgets/result.dart diff --git a/lib/main.dart b/lib/main.dart index f5b627d..9a81263 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,11 +3,12 @@ import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; import 'package:flutter_icons/flutter_icons.dart'; -import 'src/mathbox.dart'; -import 'src/result.dart'; -import 'src/mybutton.dart'; -import 'src/mathmodel.dart'; -import 'src/settingpage.dart'; +import 'package:num_plus_plus/src/widgets/mathbox.dart'; +import 'package:num_plus_plus/src/widgets/result.dart'; +import 'package:num_plus_plus/src/widgets/matrixbutton.dart'; +import 'package:num_plus_plus/src/widgets/keyboard.dart'; +import 'package:num_plus_plus/src/backend/mathmodel.dart'; +import 'package:num_plus_plus/src/pages/settingpage.dart'; void main() { runApp(MyApp()); diff --git a/lib/src/function.dart b/lib/src/backend/function.dart similarity index 100% rename from lib/src/function.dart rename to lib/src/backend/function.dart diff --git a/lib/src/latex.dart b/lib/src/backend/latex.dart similarity index 99% rename from lib/src/latex.dart rename to lib/src/backend/latex.dart index 5c4089a..eeb158e 100644 --- a/lib/src/latex.dart +++ b/lib/src/backend/latex.dart @@ -3,7 +3,7 @@ import 'package:math_expressions/math_expressions.dart'; import 'package:linalg/linalg.dart'; import 'dart:math' as math; -import 'mathmodel.dart'; +import 'package:num_plus_plus/src/backend/mathmodel.dart'; abstract class Parser { final bool isRadMode; diff --git a/lib/src/mathmodel.dart b/lib/src/backend/mathmodel.dart similarity index 98% rename from lib/src/mathmodel.dart rename to lib/src/backend/mathmodel.dart index 42b64cf..dd3ae02 100644 --- a/lib/src/mathmodel.dart +++ b/lib/src/backend/mathmodel.dart @@ -3,7 +3,7 @@ import 'package:math_expressions/math_expressions.dart'; import 'package:linalg/linalg.dart'; // import 'function.dart'; -import 'latex.dart'; +import 'package:num_plus_plus/src/backend/latex.dart'; class MathModel with ChangeNotifier { List _latexExp = ['']; diff --git a/lib/src/settingpage.dart b/lib/src/pages/settingpage.dart similarity index 98% rename from lib/src/settingpage.dart rename to lib/src/pages/settingpage.dart index c74036a..c482ad1 100644 --- a/lib/src/settingpage.dart +++ b/lib/src/pages/settingpage.dart @@ -4,7 +4,7 @@ import 'package:shared_preferences/shared_preferences.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:flutter_icons/flutter_icons.dart'; -import 'mathmodel.dart'; +import 'package:num_plus_plus/src/backend/mathmodel.dart'; class SettingPage extends StatelessWidget { @override diff --git a/lib/src/mybutton.dart b/lib/src/widgets/keyboard.dart similarity index 98% rename from lib/src/mybutton.dart rename to lib/src/widgets/keyboard.dart index 775f8ca..8509205 100644 --- a/lib/src/mybutton.dart +++ b/lib/src/widgets/keyboard.dart @@ -3,9 +3,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_icons/flutter_icons.dart'; import 'package:provider/provider.dart'; -import 'mathbox.dart'; -import 'mathmodel.dart'; -import 'settingpage.dart'; +import 'package:num_plus_plus/src/widgets/mathbox.dart'; +import 'package:num_plus_plus/src/pages/settingpage.dart'; +import 'package:num_plus_plus/src/backend/mathmodel.dart'; class MyButton extends StatelessWidget { final Widget child; diff --git a/lib/src/mathbox.dart b/lib/src/widgets/mathbox.dart similarity index 99% rename from lib/src/mathbox.dart rename to lib/src/widgets/mathbox.dart index ef19a5a..b9ec97f 100644 --- a/lib/src/mathbox.dart +++ b/lib/src/widgets/mathbox.dart @@ -7,7 +7,7 @@ import 'package:flutter/services.dart'; import 'package:mime/mime.dart'; import 'package:provider/provider.dart'; -import 'mathmodel.dart'; +import 'package:num_plus_plus/src/backend/mathmodel.dart'; class Server { // class from inAppBrowser diff --git a/lib/src/result.dart b/lib/src/widgets/matrixbutton.dart similarity index 67% rename from lib/src/result.dart rename to lib/src/widgets/matrixbutton.dart index 44f82a6..3d1704d 100644 --- a/lib/src/result.dart +++ b/lib/src/widgets/matrixbutton.dart @@ -1,62 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:num_plus_plus/src/mathbox.dart'; import 'package:provider/provider.dart'; -import 'mathmodel.dart'; - -class Result extends StatefulWidget { - @override - _ResultState createState() => _ResultState(); -} - -class _ResultState extends State with TickerProviderStateMixin { - - AnimationController animationController; - Animation animation; - - @override - void initState() { - super.initState(); - final mathModel = Provider.of(context, listen: false); - animationController = AnimationController(duration: const Duration(milliseconds: 400),vsync: this); - mathModel.equalAnimation = animationController; - final curve = CurvedAnimation(parent: animationController, curve: Curves.easeInOutBack); - animation = Tween(begin: 30.0, end: 60.0).animate(curve) - ..addListener(() {setState(() {});}); - } - - @override - void dispose() { - animationController.dispose(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return Container( - height: animation.value, - width: double.infinity, - alignment: Alignment.centerRight, - child: Consumer( - builder: (_, model, __) { - String text; - if (model.result!='' && animationController.status == AnimationStatus.dismissed) { - text = '= ' + model.result; - } else { - text = model.result; - } - return SelectableText( - text, - style: TextStyle( - fontFamily: 'Minion-Pro', - fontSize: animation.value - 5, - ), - ); - }, - ), - ); - } -} +import 'package:num_plus_plus/src/backend/mathmodel.dart'; +import 'package:num_plus_plus/src/widgets/mathbox.dart'; class SingleMatrixButton extends StatelessWidget { final Widget child; diff --git a/lib/src/widgets/result.dart b/lib/src/widgets/result.dart new file mode 100644 index 0000000..6c37cb8 --- /dev/null +++ b/lib/src/widgets/result.dart @@ -0,0 +1,58 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import 'package:num_plus_plus/src/backend/mathmodel.dart'; + +class Result extends StatefulWidget { + @override + _ResultState createState() => _ResultState(); +} + +class _ResultState extends State with TickerProviderStateMixin { + + AnimationController animationController; + Animation animation; + + @override + void initState() { + super.initState(); + final mathModel = Provider.of(context, listen: false); + animationController = AnimationController(duration: const Duration(milliseconds: 400),vsync: this); + mathModel.equalAnimation = animationController; + final curve = CurvedAnimation(parent: animationController, curve: Curves.easeInOutBack); + animation = Tween(begin: 30.0, end: 60.0).animate(curve) + ..addListener(() {setState(() {});}); + } + + @override + void dispose() { + animationController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Container( + height: animation.value, + width: double.infinity, + alignment: Alignment.centerRight, + child: Consumer( + builder: (_, model, __) { + String text; + if (model.result!='' && animationController.status == AnimationStatus.dismissed) { + text = '= ' + model.result; + } else { + text = model.result; + } + return SelectableText( + text, + style: TextStyle( + fontFamily: 'Minion-Pro', + fontSize: animation.value - 5, + ), + ); + }, + ), + ); + } +} diff --git a/test/latex_parser_test.dart b/test/latex_parser_test.dart index cd6bf39..0911e67 100644 --- a/test/latex_parser_test.dart +++ b/test/latex_parser_test.dart @@ -1,6 +1,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:math_expressions/math_expressions.dart'; -import 'package:num_plus_plus/src/latex.dart'; + +import 'package:num_plus_plus/src/backend/latex.dart'; void main() { test('Unit Test', () { diff --git a/test/matrix_test.dart b/test/matrix_test.dart index 2e17735..d479ab6 100644 --- a/test/matrix_test.dart +++ b/test/matrix_test.dart @@ -1,7 +1,8 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:num_plus_plus/src/latex.dart'; import 'package:linalg/linalg.dart'; +import 'package:num_plus_plus/src/backend/latex.dart'; + void main() { test('Parser Test', () { const matrixString1 = r'\begin{bmatrix}1&2\\3&4\end{bmatrix}\begin{bmatrix}1&2\\3&4\end{bmatrix}';