Skip to content

Commit

Permalink
Merge upstream to get the new dart formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
julien4215 committed Dec 16, 2024
2 parents c5d8fdc + 8130787 commit 3edcebe
Show file tree
Hide file tree
Showing 365 changed files with 12,836 additions and 20,828 deletions.
4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ analyzer:
plugins:
- custom_lint

formatter:
page_width: 100

linter:
rules:
require_trailing_commas: false
prefer_single_quotes: true
always_use_package_imports: false
avoid_redundant_argument_values: false
Expand Down
151 changes: 64 additions & 87 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,20 @@ class AppInitializationScreen extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
ref.listen<AsyncValue<PreloadedData>>(
preloadedDataProvider,
(_, state) {
if (state.hasValue || state.hasError) {
FlutterNativeSplash.remove();
}
},
);
ref.listen<AsyncValue<PreloadedData>>(preloadedDataProvider, (_, state) {
if (state.hasValue || state.hasError) {
FlutterNativeSplash.remove();
}
});

return ref.watch(preloadedDataProvider).when(
return ref
.watch(preloadedDataProvider)
.when(
data: (_) => const Application(),
// loading screen is handled by the native splash screen
loading: () => const SizedBox.shrink(),
error: (err, st) {
debugPrint(
'SEVERE: [App] could not initialize app; $err\n$st',
);
debugPrint('SEVERE: [App] could not initialize app; $err\n$st');
return const SizedBox.shrink();
},
);
Expand Down Expand Up @@ -88,8 +85,7 @@ class _AppState extends ConsumerState<Application> {

// Play registered moves whenever the app comes back online.
if (prevWasOffline && currentIsOnline) {
final nbMovesPlayed =
await ref.read(correspondenceServiceProvider).playRegisteredMoves();
final nbMovesPlayed = await ref.read(correspondenceServiceProvider).playRegisteredMoves();
if (nbMovesPlayed > 0) {
ref.invalidate(ongoingGamesProvider);
}
Expand Down Expand Up @@ -125,22 +121,18 @@ class _AppState extends ConsumerState<Application> {
final generalPrefs = ref.watch(generalPreferencesProvider);

final brightness = ref.watch(currentBrightnessProvider);
final boardTheme = ref.watch(
boardPreferencesProvider.select((state) => state.boardTheme),
);
final boardTheme = ref.watch(boardPreferencesProvider.select((state) => state.boardTheme));

final remainingHeight = estimateRemainingHeightLeftBoard(context);

return DynamicColorBuilder(
builder: (lightColorScheme, darkColorScheme) {
// TODO remove this workaround when the dynamic_color colorScheme bug is fixed
// See: https://github.com/material-foundation/flutter-packages/issues/574
final (
fixedLightScheme,
fixedDarkScheme
) = lightColorScheme != null && darkColorScheme != null
? _generateDynamicColourSchemes(lightColorScheme, darkColorScheme)
: (null, null);
final (fixedLightScheme, fixedDarkScheme) =
lightColorScheme != null && darkColorScheme != null
? _generateDynamicColourSchemes(lightColorScheme, darkColorScheme)
: (null, null);

final isTablet = isTabletOrLarger(context);

Expand All @@ -151,33 +143,29 @@ class _AppState extends ConsumerState<Application> {
generalPrefs.systemColors && dynamicColorScheme != null
? dynamicColorScheme
: ColorScheme.fromSeed(
seedColor: boardTheme.colors.darkSquare,
brightness: brightness,
);
seedColor: boardTheme.colors.darkSquare,
brightness: brightness,
);

final cupertinoThemeData = CupertinoThemeData(
primaryColor: colorScheme.primary,
primaryContrastingColor: colorScheme.onPrimary,
brightness: brightness,
textTheme: CupertinoTheme.of(context).textTheme.copyWith(
primaryColor: colorScheme.primary,
textStyle: CupertinoTheme.of(context)
.textTheme
.textStyle
.copyWith(color: Styles.cupertinoLabelColor),
navTitleTextStyle: CupertinoTheme.of(context)
.textTheme
.navTitleTextStyle
.copyWith(color: Styles.cupertinoTitleColor),
navLargeTitleTextStyle: CupertinoTheme.of(context)
.textTheme
.navLargeTitleTextStyle
.copyWith(color: Styles.cupertinoTitleColor),
),
primaryColor: colorScheme.primary,
textStyle: CupertinoTheme.of(
context,
).textTheme.textStyle.copyWith(color: Styles.cupertinoLabelColor),
navTitleTextStyle: CupertinoTheme.of(
context,
).textTheme.navTitleTextStyle.copyWith(color: Styles.cupertinoTitleColor),
navLargeTitleTextStyle: CupertinoTheme.of(
context,
).textTheme.navLargeTitleTextStyle.copyWith(color: Styles.cupertinoTitleColor),
),
scaffoldBackgroundColor: Styles.cupertinoScaffoldColor,
barBackgroundColor: isTablet
? Styles.cupertinoTabletAppBarColor
: Styles.cupertinoAppBarColor,
barBackgroundColor:
isTablet ? Styles.cupertinoTabletAppBarColor : Styles.cupertinoAppBarColor,
);

return MaterialApp(
Expand All @@ -187,47 +175,40 @@ class _AppState extends ConsumerState<Application> {
locale: generalPrefs.locale,
theme: ThemeData.from(
colorScheme: colorScheme,
textTheme: Theme.of(context).platform == TargetPlatform.iOS
? brightness == Brightness.light
? Typography.blackCupertino
: Styles.whiteCupertinoTextTheme
: null,
textTheme:
Theme.of(context).platform == TargetPlatform.iOS
? brightness == Brightness.light
? Typography.blackCupertino
: Styles.whiteCupertinoTextTheme
: null,
).copyWith(
cupertinoOverrideTheme: cupertinoThemeData,
navigationBarTheme: NavigationBarTheme.of(context).copyWith(
height: remainingHeight < kSmallRemainingHeightLeftBoardThreshold
? 60
: null,
height: remainingHeight < kSmallRemainingHeightLeftBoardThreshold ? 60 : null,
),
extensions: [
lichessCustomColors.harmonized(colorScheme),
],
extensions: [lichessCustomColors.harmonized(colorScheme)],
),
themeMode: switch (generalPrefs.themeMode) {
BackgroundThemeMode.light => ThemeMode.light,
BackgroundThemeMode.dark => ThemeMode.dark,
BackgroundThemeMode.system => ThemeMode.system,
},
builder: Theme.of(context).platform == TargetPlatform.iOS
? (context, child) {
return CupertinoTheme(
data: cupertinoThemeData,
child: IconTheme.merge(
data: IconThemeData(
color: CupertinoTheme.of(context)
.textTheme
.textStyle
.color,
builder:
Theme.of(context).platform == TargetPlatform.iOS
? (context, child) {
return CupertinoTheme(
data: cupertinoThemeData,
child: IconTheme.merge(
data: IconThemeData(
color: CupertinoTheme.of(context).textTheme.textStyle.color,
),
child: Material(child: child),
),
child: Material(child: child),
),
);
}
: null,
);
}
: null,
home: const BottomNavScaffold(),
navigatorObservers: [
rootNavPageRouteObserver,
],
navigatorObservers: [rootNavPageRouteObserver],
);
},
);
Expand All @@ -249,28 +230,24 @@ class _AppState extends ConsumerState<Application> {
final lightAdditionalColours = _extractAdditionalColours(lightBase);
final darkAdditionalColours = _extractAdditionalColours(darkBase);

final lightScheme =
_insertAdditionalColours(lightBase, lightAdditionalColours);
final lightScheme = _insertAdditionalColours(lightBase, lightAdditionalColours);
final darkScheme = _insertAdditionalColours(darkBase, darkAdditionalColours);

return (lightScheme.harmonized(), darkScheme.harmonized());
}

List<Color> _extractAdditionalColours(ColorScheme scheme) => [
scheme.surface,
scheme.surfaceDim,
scheme.surfaceBright,
scheme.surfaceContainerLowest,
scheme.surfaceContainerLow,
scheme.surfaceContainer,
scheme.surfaceContainerHigh,
scheme.surfaceContainerHighest,
];
scheme.surface,
scheme.surfaceDim,
scheme.surfaceBright,
scheme.surfaceContainerLowest,
scheme.surfaceContainerLow,
scheme.surfaceContainer,
scheme.surfaceContainerHigh,
scheme.surfaceContainerHighest,
];

ColorScheme _insertAdditionalColours(
ColorScheme scheme,
List<Color> additionalColours,
) =>
ColorScheme _insertAdditionalColours(ColorScheme scheme, List<Color> additionalColours) =>
scheme.copyWith(
surface: additionalColours[0],
surfaceDim: additionalColours[1],
Expand Down
10 changes: 3 additions & 7 deletions lib/src/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,10 @@ class AppLichessBinding extends LichessBinding {

@override
Future<void> initializeFirebase() async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

if (kReleaseMode) {
FlutterError.onError =
FirebaseCrashlytics.instance.recordFlutterFatalError;
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
PlatformDispatcher.instance.onError = (error, stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
return true;
Expand All @@ -154,8 +151,7 @@ class AppLichessBinding extends LichessBinding {
}

@override
Stream<RemoteMessage> get firebaseMessagingOnMessage =>
FirebaseMessaging.onMessage;
Stream<RemoteMessage> get firebaseMessagingOnMessage => FirebaseMessaging.onMessage;

@override
Stream<RemoteMessage> get firebaseMessagingOnMessageOpenedApp =>
Expand Down
13 changes: 4 additions & 9 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

const kLichessHost = String.fromEnvironment(
'LICHESS_HOST',
defaultValue: 'lichess.dev',
);
const kLichessHost = String.fromEnvironment('LICHESS_HOST', defaultValue: 'lichess.dev');

const kLichessWSHost = String.fromEnvironment(
'LICHESS_WS_HOST',
Expand All @@ -26,8 +23,7 @@ const kLichessOpeningExplorerHost = String.fromEnvironment(
defaultValue: 'explorer.lichess.ovh',
);

const kLichessDevUser =
String.fromEnvironment('LICHESS_DEV_USER', defaultValue: 'lichess');
const kLichessDevUser = String.fromEnvironment('LICHESS_DEV_USER', defaultValue: 'lichess');
const kLichessDevPassword = String.fromEnvironment('LICHESS_DEV_PASSWORD');

const kLichessClientId = 'lichess_mobile';
Expand All @@ -50,9 +46,8 @@ const kFlexGoldenRatioBase = 100000000000;
const kFlexGoldenRatio = 161803398875;

/// Use same box shadows as material widgets with elevation 1.
final List<BoxShadow> boardShadows = defaultTargetPlatform == TargetPlatform.iOS
? <BoxShadow>[]
: kElevationToShadow[1]!;
final List<BoxShadow> boardShadows =
defaultTargetPlatform == TargetPlatform.iOS ? <BoxShadow>[] : kElevationToShadow[1]!;

const kCardTextScaleFactor = 1.64;
const kMaxClockTextScaleFactor = 1.94;
Expand Down
21 changes: 4 additions & 17 deletions lib/src/db/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,8 @@ Future<int?> sqliteVersion(Ref ref) async {

Future<int?> _getDatabaseVersion(Database db) async {
try {
final versionStr = (await db.rawQuery('SELECT sqlite_version()'))
.first
.values
.first
.toString();
final versionCells =
versionStr.split('.').map((i) => int.parse(i)).toList();
final versionStr = (await db.rawQuery('SELECT sqlite_version()')).first.values.first.toString();
final versionCells = versionStr.split('.').map((i) => int.parse(i)).toList();
return versionCells[0] * 100000 + versionCells[1] * 1000 + versionCells[2];
} catch (_) {
return null;
Expand Down Expand Up @@ -71,11 +66,7 @@ Future<Database> openAppDatabase(DatabaseFactory dbFactory, String path) async {
_deleteOldEntries(db, 'puzzle', puzzleTTL),
_deleteOldEntries(db, 'correspondence_game', corresGameTTL),
_deleteOldEntries(db, 'game', gameTTL),
_deleteOldEntries(
db,
'chat_read_messages',
chatReadMessagesTTL,
),
_deleteOldEntries(db, 'chat_read_messages', chatReadMessagesTTL),
]);
},
onCreate: (db, version) async {
Expand Down Expand Up @@ -190,11 +181,7 @@ Future<void> _deleteOldEntries(Database db, String table, Duration ttl) async {
return;
}

await db.delete(
table,
where: 'lastModified < ?',
whereArgs: [date.toIso8601String()],
);
await db.delete(table, where: 'lastModified < ?', whereArgs: [date.toIso8601String()]);
}

Future<bool> _doesTableExist(Database db, String table) async {
Expand Down
11 changes: 3 additions & 8 deletions lib/src/db/openings_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,12 @@ Future<Database> _openDb(String path) async {
});

// Copy from asset
final ByteData data =
await rootBundle.load(p.url.join('assets', 'chess_openings.db'));
final List<int> bytes =
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
final ByteData data = await rootBundle.load(p.url.join('assets', 'chess_openings.db'));
final List<int> bytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);

// Write and flush the bytes written
await File(path).writeAsBytes(bytes, flush: true);
}

return databaseFactory.openDatabase(
path,
options: OpenDatabaseOptions(readOnly: true),
);
return databaseFactory.openDatabase(path, options: OpenDatabaseOptions(readOnly: true));
}
6 changes: 3 additions & 3 deletions lib/src/db/secure_storage.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

AndroidOptions _getAndroidOptions() => const AndroidOptions(
encryptedSharedPreferences: true,
sharedPreferencesName: 'org.lichess.mobile.secure',
);
encryptedSharedPreferences: true,
sharedPreferencesName: 'org.lichess.mobile.secure',
);

class SecureStorage extends FlutterSecureStorage {
const SecureStorage._({super.aOptions});
Expand Down
Loading

0 comments on commit 3edcebe

Please sign in to comment.