restructure

- move list_item_divider into lib/shared
- move lib/engine into lib/services/engine

unify Import style

- I've unified the way files are imported. We now use absolute imports everywhere.

This is not a must but I find it more usefull.

cleanup imports

- prefer using part files where needed
This commit is contained in:
Leptopoda 2021-10-08 19:14:33 +02:00
parent 339af39579
commit 8727dc2a87
No known key found for this signature in database
GPG Key ID: 661B059EDE309F11
24 changed files with 66 additions and 104 deletions

View File

@ -19,10 +19,10 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/screens/list_item_divider.dart';
import 'package:sanmill/shared/common/config.dart';
import 'package:sanmill/shared/common/constants.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/shared/list_item_divider.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
Map<String, Strings> languageCodeToStrings = {
@ -520,9 +520,7 @@ class Resources {
}
Future<void> setLanguage(
BuildContext context,
Function(String?)? callback,
) async {
BuildContext context, Function(String?)? callback) async {
final languageColumn = Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
@ -572,7 +570,7 @@ Bidirectionality getBidirectionality(BuildContext context) {
currentLocale.languageCode == "he" ||
currentLocale.languageCode == "ps" ||
currentLocale.languageCode == "ur") {
debugPrint("bidirectionality: RTL");
print("bidirectionality: RTL");
return Bidirectionality.rightToLeft;
} else {
return Bidirectionality.leftToRight;
@ -593,5 +591,5 @@ void setSpecialCountryAndRegion(BuildContext context) {
break;
}
debugPrint("Set Special Country and Region to $specialCountryAndRegion.");
print("Set Special Country and Region to $specialCountryAndRegion.");
}

View File

@ -16,7 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:async';
import 'dart:io';
import 'dart:ui';
@ -34,8 +33,6 @@ import 'package:sanmill/services/audios.dart';
import 'package:sanmill/shared/common/constants.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
import 'services/audios.dart';
Future<void> main() async {
final catcher = Catcher(
rootWidget: BetterFeedback(

View File

@ -17,12 +17,11 @@
*/
import 'package:flutter/foundation.dart';
import 'package:sanmill/engine/engine.dart';
import 'package:sanmill/mill/position.dart';
import 'package:sanmill/mill/types.dart';
import 'package:sanmill/services/engine/engine.dart';
import 'package:sanmill/shared/common/config.dart';
import 'position.dart';
import 'types.dart';
enum PlayerType { human, AI }
Map<String, bool> isAi = {PieceColor.white: false, PieceColor.black: true};

View File

@ -16,8 +16,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'position.dart';
import 'rule.dart';
import 'package:sanmill/mill/position.dart';
import 'package:sanmill/mill/rule.dart';
class Mills {
const Mills._();

View File

@ -17,16 +17,14 @@
*/
import 'package:flutter/foundation.dart';
import 'package:sanmill/engine/engine.dart';
import 'package:sanmill/mill/game.dart';
import 'package:sanmill/mill/mills.dart';
import 'package:sanmill/mill/recorder.dart';
import 'package:sanmill/mill/rule.dart';
import 'package:sanmill/mill/types.dart';
import 'package:sanmill/mill/zobrist.dart';
import 'package:sanmill/services/audios.dart';
import 'mills.dart';
import 'types.dart';
import 'zobrist.dart';
import 'package:sanmill/services/engine/engine.dart';
List<int> posKeyHistory = [];

View File

@ -17,11 +17,10 @@
*/
import 'package:flutter/foundation.dart';
import 'package:sanmill/mill/position.dart';
import 'package:sanmill/mill/types.dart';
import 'package:sanmill/shared/common/config.dart';
import 'position.dart';
import 'types.dart';
// TODO
class GameRecorder {
int cur = -1;

View File

@ -24,15 +24,14 @@ import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:sanmill/generated/flutter_version.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/screens/settings/settings_list_tile.dart';
import 'package:sanmill/screens/license_page.dart';
import 'package:sanmill/screens/oss_license_page.dart';
import 'package:sanmill/shared/common/constants.dart';
import 'package:sanmill/shared/list_item_divider.dart';
import 'package:sanmill/shared/settings/settings_list_tile.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
import 'package:url_launcher/url_launcher.dart';
import 'license_page.dart';
import 'list_item_divider.dart';
import 'oss_license_page.dart';
class AboutPage extends StatelessWidget {
final String tag = "[about] ";

View File

@ -16,15 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/mill/game.dart';
import 'package:sanmill/mill/types.dart';
import 'package:sanmill/shared/common/config.dart';
import 'package:sanmill/shared/painters/board_painter.dart';
import 'package:sanmill/shared/painters/pieces_painter.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
part of 'package:sanmill/screens/game_page/game_page.dart';
typedef BoardTapCallback = dynamic Function(int index);

View File

@ -16,15 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:async';
//import 'dart:typed_data';
import 'dart:async';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sanmill/engine/engine.dart';
import 'package:sanmill/engine/native_engine.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/main.dart';
@ -32,9 +30,10 @@ import 'package:sanmill/mill/game.dart';
import 'package:sanmill/mill/position.dart';
import 'package:sanmill/mill/rule.dart';
import 'package:sanmill/mill/types.dart';
import 'package:sanmill/screens/board.dart';
import 'package:sanmill/screens/game_settings_page.dart';
import 'package:sanmill/services/audios.dart';
import 'package:sanmill/services/engine/engine.dart';
import 'package:sanmill/services/engine/native_engine.dart';
import 'package:sanmill/shared/common/config.dart';
import 'package:sanmill/shared/common/constants.dart';
import 'package:sanmill/shared/dialog.dart';
@ -45,6 +44,10 @@ import 'package:sanmill/shared/theme/app_theme.dart';
import 'package:stack_trace/stack_trace.dart';
part 'package:sanmill/screens/game_page/game_page_tool_bar.dart';
part 'package:sanmill/screens/game_page/board.dart';
part 'package:sanmill/shared/painters/board_painter.dart';
part 'package:sanmill/shared/painters/pieces_painter.dart';
part 'package:sanmill/shared/painters/painter_base.dart';
double boardWidth = 0.0;

View File

@ -21,16 +21,15 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/screens/settings/settings_card.dart';
import 'package:sanmill/screens/settings/settings_list_tile.dart';
import 'package:sanmill/screens/settings/settings_switch_list_tile.dart';
import 'package:sanmill/screens/env_page.dart';
import 'package:sanmill/shared/common/config.dart';
import 'package:sanmill/shared/common/settings.dart';
import 'package:sanmill/shared/dialog.dart';
import 'package:sanmill/shared/settings/settings_card.dart';
import 'package:sanmill/shared/settings/settings_list_tile.dart';
import 'package:sanmill/shared/settings/settings_switch_list_tile.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
import '../shared/dialog.dart';
import 'env_page.dart';
class Developer {
const Developer._();
static bool developerModeEnabled = false;

View File

@ -16,16 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:async';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:flutter/material.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/screens/game_settings_page.dart';
import 'package:sanmill/shared/common/config.dart';
import 'package:sanmill/shared/common/constants.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
part of 'package:sanmill/screens/navigation_home_screen.dart';
enum DrawerIndex {
humanVsAi,

View File

@ -19,19 +19,20 @@
import 'dart:io';
import 'dart:typed_data';
import 'package:animated_text_kit/animated_text_kit.dart';
import 'package:feedback/feedback.dart';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:flutter_email_sender/flutter_email_sender.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:path_provider/path_provider.dart';
import 'package:sanmill/engine/engine.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/mill/game.dart';
import 'package:sanmill/screens/about_page.dart';
import 'package:sanmill/screens/drawer_user_controller.dart';
import 'package:sanmill/screens/game_page/game_page.dart';
import 'package:sanmill/screens/game_settings_page.dart';
import 'package:sanmill/screens/help_screen.dart';
import 'package:sanmill/screens/home_drawer.dart';
import 'package:sanmill/screens/personalization_settings_page.dart';
import 'package:sanmill/screens/rule_settings_page.dart';
import 'package:sanmill/services/engine/engine.dart';
@ -39,6 +40,9 @@ import 'package:sanmill/shared/common/config.dart';
import 'package:sanmill/shared/common/constants.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
part 'package:sanmill/screens/home_drawer.dart';
part 'package:sanmill/shared/drawer_controller.dart';
class NavigationHomeScreen extends StatefulWidget {
@override
_NavigationHomeScreenState createState() => _NavigationHomeScreenState();
@ -59,7 +63,7 @@ class _NavigationHomeScreenState extends State<NavigationHomeScreen> {
Widget build(BuildContext context) {
return Material(
color: AppTheme.navigationHomeScreenBackgroundColor,
child: DrawerUserController(
child: DrawerController(
screenIndex: drawerIndex,
drawerWidth: MediaQuery.of(context).size.width * 0.75,
onDrawerCall: changeIndex,

View File

@ -20,11 +20,11 @@ import 'package:flutter/material.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/screens/settings/settings_card.dart';
import 'package:sanmill/screens/settings/settings_list_tile.dart';
import 'package:sanmill/screens/settings/settings_switch_list_tile.dart';
import 'package:sanmill/shared/common/config.dart';
import 'package:sanmill/shared/common/constants.dart';
import 'package:sanmill/shared/settings/settings_card.dart';
import 'package:sanmill/shared/settings/settings_list_tile.dart';
import 'package:sanmill/shared/settings/settings_switch_list_tile.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
class PersonalizationSettingsPage extends StatefulWidget {

View File

@ -20,14 +20,13 @@ import 'package:flutter/material.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/mill/rule.dart';
import 'package:sanmill/screens/settings/settings_card.dart';
import 'package:sanmill/screens/settings/settings_list_tile.dart';
import 'package:sanmill/screens/settings/settings_switch_list_tile.dart';
import 'package:sanmill/shared/common/config.dart';
import 'package:sanmill/shared/settings/settings_card.dart';
import 'package:sanmill/shared/settings/settings_list_tile.dart';
import 'package:sanmill/shared/settings/settings_switch_list_tile.dart';
import 'package:sanmill/shared/snack_bar.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
import '../shared/snack_bar.dart';
class RuleSettingsPage extends StatefulWidget {
@override
_RuleSettingsPageState createState() => _RuleSettingsPageState();

View File

@ -22,10 +22,9 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sanmill/mill/position.dart';
import 'package:sanmill/mill/types.dart';
import 'package:sanmill/services/engine/engine.dart';
import 'package:sanmill/shared/common/config.dart';
import 'engine.dart';
class NativeEngine extends Engine {
static const platform = MethodChannel('com.calcitem.sanmill/engine');
bool isActive = false;
@ -55,8 +54,13 @@ class NativeEngine extends Engine {
return platform.invokeMethod('isReady');
}
Future<bool> isThinking() async {
return platform.invokeMethod<bool>('isThinking') as Future<bool>;
FutureOr<bool> isThinking() async {
final _isThinking = await platform.invokeMethod<bool>('isThinking');
if (_isThinking is bool) {
return _isThinking;
} else {
throw 'Invalid platform response. Expected a value of type bool';
}
}
@override

View File

@ -16,16 +16,10 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/l10n/resources.dart';
import 'package:sanmill/screens/home_drawer.dart';
import 'package:sanmill/shared/common/config.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
part of 'package:sanmill/screens/navigation_home_screen.dart';
class DrawerUserController extends StatefulWidget {
const DrawerUserController({
class DrawerController extends StatefulWidget {
const DrawerController({
Key? key,
this.drawerWidth = AppTheme.drawerWidth,
required this.onDrawerCall,
@ -45,10 +39,10 @@ class DrawerUserController extends StatefulWidget {
final DrawerIndex screenIndex;
@override
_DrawerUserControllerState createState() => _DrawerUserControllerState();
_DrawerControllerState createState() => _DrawerControllerState();
}
class _DrawerUserControllerState extends State<DrawerUserController>
class _DrawerControllerState extends State<DrawerController>
with TickerProviderStateMixin {
late final ScrollController scrollController;
late final AnimationController iconAnimationController;

View File

@ -16,14 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:sanmill/mill/game.dart';
import 'package:sanmill/mill/types.dart';
import 'package:sanmill/screens/game_page/game_page.dart';
import 'package:sanmill/shared/common/config.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
import 'painter_base.dart';
part of 'package:sanmill/screens/game_page/game_page.dart';
class BoardPainter extends PiecesBasePainter {
BoardPainter({required double width}) : super(width: width);

View File

@ -16,8 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
part of 'package:sanmill/screens/game_page/game_page.dart';
abstract class PiecesBasePainter extends CustomPainter {
final double width;

View File

@ -16,13 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'package:flutter/material.dart';
import 'package:sanmill/mill/position.dart';
import 'package:sanmill/mill/types.dart';
import 'package:sanmill/shared/common/config.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
import 'painter_base.dart';
part of 'package:sanmill/screens/game_page/game_page.dart';
class PiecePaintParam {
final String piece;

View File

@ -17,7 +17,7 @@
*/
import 'package:flutter/material.dart';
import 'package:sanmill/screens/list_item_divider.dart';
import 'package:sanmill/shared/list_item_divider.dart';
import 'package:sanmill/shared/theme/app_theme.dart';
class SettingsCard extends StatelessWidget {