-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ea3b31
commit 694790f
Showing
9 changed files
with
508 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage-9.2.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.4\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.5.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage-9.2.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.27\\\\","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_android-2.3.1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"flutter_secure_storage_macos","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_macos-3.1.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.4\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.5.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"flutter_secure_storage_linux","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_linux-1.2.1\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_linux","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.10\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_linux-2.4.1\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"flutter_secure_storage_windows","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_windows-3.1.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_windows","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.7\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_windows-2.4.1\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"flutter_secure_storage_web","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_web-1.2.1\\\\","dependencies":[]},{"name":"shared_preferences_web","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_web-2.4.2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":["flutter_secure_storage_linux","flutter_secure_storage_macos","flutter_secure_storage_web","flutter_secure_storage_windows"]},{"name":"flutter_secure_storage_linux","dependencies":[]},{"name":"flutter_secure_storage_macos","dependencies":[]},{"name":"flutter_secure_storage_web","dependencies":[]},{"name":"flutter_secure_storage_windows","dependencies":["path_provider"]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2024-08-22 20:54:16.685812","version":"3.24.0","swift_package_manager_enabled":false} | ||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage-9.2.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.4\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.5.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage-9.2.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_android","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.0.27\\\\","native_build":true,"dependencies":[]},{"name":"shared_preferences_android","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_android-2.3.1\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"flutter_secure_storage_macos","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_macos-3.1.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.2.4\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]},{"name":"shared_preferences_foundation","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_foundation-2.5.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"flutter_secure_storage_linux","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_linux-1.2.1\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_linux","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.1.10\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_linux","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_linux-2.4.1\\\\","native_build":false,"dependencies":["path_provider_linux"]}],"windows":[{"name":"flutter_secure_storage_windows","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_windows-3.1.2\\\\","native_build":true,"dependencies":[]},{"name":"path_provider_windows","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.1.7\\\\","native_build":false,"dependencies":[]},{"name":"shared_preferences_windows","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_windows-2.4.1\\\\","native_build":false,"dependencies":["path_provider_windows"]}],"web":[{"name":"flutter_secure_storage_web","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\flutter_secure_storage_web-1.2.1\\\\","dependencies":[]},{"name":"shared_preferences_web","path":"E:\\\\flutter\\\\cache\\\\hosted\\\\pub.dev\\\\shared_preferences_web-2.4.2\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":["flutter_secure_storage_linux","flutter_secure_storage_macos","flutter_secure_storage_web","flutter_secure_storage_windows"]},{"name":"flutter_secure_storage_linux","dependencies":[]},{"name":"flutter_secure_storage_macos","dependencies":[]},{"name":"flutter_secure_storage_web","dependencies":[]},{"name":"flutter_secure_storage_windows","dependencies":["path_provider"]},{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_android","shared_preferences_foundation","shared_preferences_linux","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_android","dependencies":[]},{"name":"shared_preferences_foundation","dependencies":[]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2024-08-22 21:55:03.192752","version":"3.24.0","swift_package_manager_enabled":false} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:playx_theme/playx_theme.dart'; | ||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; | ||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; | ||
|
||
void main() { | ||
group('PlayxColors', () { | ||
test('Default constructor initializes with default values', () { | ||
const colors = PlayxColors(); | ||
|
||
expect(colors.primary, PlayxColors.blueMain); | ||
expect(colors.onPrimary, PlayxColors.white); | ||
expect(colors.primaryContainer, PlayxColors.white); | ||
expect(colors.onPrimaryContainer, PlayxColors.black); | ||
expect(colors.secondary, Colors.teal); | ||
expect(colors.onSecondary, PlayxColors.white); | ||
expect(colors.secondaryContainer, PlayxColors.white); | ||
expect(colors.onSecondaryContainer, PlayxColors.black); | ||
expect(colors.tertiary, PlayxColors.purpleMain); | ||
expect(colors.onTertiary, PlayxColors.white); | ||
expect(colors.error, PlayxColors.red); | ||
expect(colors.onError, PlayxColors.white); | ||
expect(colors.errorContainer, PlayxColors.redLight); | ||
expect(colors.onErrorContainer, PlayxColors.white); | ||
expect(colors.outline, PlayxColors.black); | ||
expect(colors.outlineVariant, Colors.black12); | ||
expect(colors.surface, PlayxColors.white); | ||
expect(colors.onSurface, PlayxColors.black); | ||
expect(colors.inverseSurface, PlayxColors.black); | ||
expect(colors.onInverseSurface, PlayxColors.white); | ||
expect(colors.inversePrimary, PlayxColors.white); | ||
expect(colors.shadow, PlayxColors.black); | ||
expect(colors.scrim, PlayxColors.white); | ||
expect(colors.surfaceTint, PlayxColors.white); | ||
}); | ||
|
||
test('Custom constructor initializes with provided values', () { | ||
const customPrimary = Colors.red; | ||
const customOnPrimary = Colors.white; | ||
const colors = | ||
PlayxColors(primary: customPrimary, onPrimary: customOnPrimary); | ||
|
||
expect(colors.primary, customPrimary); | ||
expect(colors.onPrimary, customOnPrimary); | ||
}); | ||
|
||
test('fromColorScheme constructor correctly overrides values', () { | ||
const colorScheme = ColorScheme.light( | ||
primary: Colors.purple, | ||
onPrimary: Colors.orange, | ||
); | ||
|
||
final colors = PlayxColors.fromColorScheme(scheme: colorScheme); | ||
|
||
expect(colors.primary, Colors.purple); | ||
expect(colors.onPrimary, Colors.orange); | ||
}); | ||
|
||
testWidgets('of method retrieves the correct PlayxColors from context', | ||
(WidgetTester tester) async { | ||
const playxColors = PlayxColors(primary: Colors.red); | ||
|
||
final theme = XTheme( | ||
id: 'test-theme', | ||
name: 'Test Theme', | ||
themeData: ThemeData(), | ||
colors: playxColors, | ||
); | ||
|
||
SharedPreferencesAsyncPlatform.instance = | ||
InMemorySharedPreferencesAsync.empty(); | ||
|
||
await PlayxTheme.boot( | ||
config: PlayxThemeConfig( | ||
themes: [theme], | ||
)); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: PlayxThemeBuilder( | ||
child: Builder( | ||
builder: (context) { | ||
final retrievedColors = PlayxColors.of(context); | ||
expect(retrievedColors.primary, playxColors.primary); | ||
return const SizedBox.shrink(); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
}); | ||
|
||
testWidgets( | ||
'maybeOf method retrieves the correct PlayxColors from context or null', | ||
(WidgetTester tester) async { | ||
const playxColors = PlayxColors(primary: Colors.red); | ||
|
||
final theme = XTheme( | ||
id: 'test-theme', | ||
name: 'Test Theme', | ||
themeData: ThemeData(), | ||
colors: playxColors, | ||
); | ||
|
||
SharedPreferencesAsyncPlatform.instance = | ||
InMemorySharedPreferencesAsync.empty(); | ||
|
||
await PlayxTheme.boot( | ||
config: PlayxThemeConfig( | ||
themes: [theme], | ||
)); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: PlayxThemeBuilder( | ||
child: Builder( | ||
builder: (context) { | ||
final retrievedColors = PlayxColors.maybeOf(context); | ||
expect(retrievedColors?.primary, playxColors.primary); | ||
return const SizedBox.shrink(); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
|
||
// Test when no PlayxColors is available in the context | ||
await tester.pumpWidget(MaterialApp( | ||
home: Builder( | ||
builder: (context) { | ||
final retrievedColors = PlayxColors.maybeOf(context); | ||
expect(retrievedColors, isNull); | ||
return const SizedBox.shrink(); | ||
}, | ||
), | ||
)); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:playx_theme/playx_theme.dart'; | ||
import 'package:shared_preferences_platform_interface/in_memory_shared_preferences_async.dart'; | ||
import 'package:shared_preferences_platform_interface/shared_preferences_async_platform_interface.dart'; // Adjust import as needed | ||
|
||
void main() { | ||
group('XTheme', () { | ||
test('XTheme constructor should create correct instance', () { | ||
final themeData = ThemeData.light(); | ||
const cupertinoThemeData = CupertinoThemeData(); | ||
const colors = PlayxColors(); | ||
|
||
final xTheme = XTheme( | ||
id: 'theme1', | ||
name: 'Light Theme', | ||
themeData: themeData, | ||
cupertinoThemeData: cupertinoThemeData, | ||
colors: colors, | ||
isDark: false, | ||
); | ||
|
||
expect(xTheme.id, 'theme1'); | ||
expect(xTheme.name, 'Light Theme'); | ||
expect(xTheme.themeData, themeData); | ||
expect(xTheme.cupertinoThemeData, cupertinoThemeData); | ||
expect(xTheme.colors, colors); | ||
expect(xTheme.isDark, false); | ||
}); | ||
|
||
test('XTheme.builder should create correct instance', () { | ||
final initialTheme = ThemeData.light(); | ||
|
||
final xTheme = XTheme.builder( | ||
id: 'theme2', | ||
name: 'Dynamic Theme', | ||
initialTheme: initialTheme, | ||
themeBuilder: (locale) => ThemeData.dark(), | ||
cupertinoThemeBuilder: (locale) => const CupertinoThemeData(), | ||
); | ||
|
||
expect(xTheme.id, 'theme2'); | ||
expect(xTheme.name, 'Dynamic Theme'); | ||
expect(xTheme.themeData, initialTheme); | ||
expect(xTheme.themeBuilder!(null), isInstanceOf<ThemeData>()); | ||
expect(xTheme.cupertinoThemeBuilder!(null), | ||
isInstanceOf<CupertinoThemeData>()); | ||
}); | ||
|
||
test('XTheme equality and props', () { | ||
final xTheme1 = XTheme( | ||
id: 'theme1', | ||
name: 'Light Theme', | ||
themeData: ThemeData.light(), | ||
); | ||
|
||
final xTheme2 = XTheme( | ||
id: 'theme1', | ||
name: 'Light Theme', | ||
themeData: ThemeData.light(), | ||
); | ||
|
||
final xTheme3 = XTheme( | ||
id: 'theme2', | ||
name: 'Dark Theme', | ||
themeData: ThemeData.dark(), | ||
); | ||
|
||
expect(xTheme1 == xTheme2, isTrue); // Same id and name, should be equal | ||
expect(xTheme1 == xTheme3, | ||
isFalse); // Different id and name, should not be equal | ||
expect(xTheme1.props, [xTheme1.id, xTheme1.name]); | ||
}); | ||
|
||
testWidgets('XTheme.of should return current theme from context', | ||
(WidgetTester tester) async { | ||
final xTheme = XTheme( | ||
id: 'theme1', | ||
name: 'Light Theme', | ||
themeData: ThemeData.light(), | ||
); | ||
SharedPreferencesAsyncPlatform.instance = | ||
InMemorySharedPreferencesAsync.empty(); | ||
|
||
await PlayxTheme.boot( | ||
config: PlayxThemeConfig( | ||
themes: [xTheme], | ||
)); | ||
|
||
await tester.pumpWidget( | ||
PlayxThemeBuilder( | ||
child: MaterialApp( | ||
home: Builder( | ||
builder: (context) { | ||
final retrievedTheme = XTheme.of(context); | ||
expect(retrievedTheme, xTheme); | ||
return Container(); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
}); | ||
|
||
testWidgets( | ||
'XTheme.maybeOf should return current theme or null from context', | ||
(WidgetTester tester) async { | ||
final xTheme = XTheme( | ||
id: 'theme1', | ||
name: 'Light Theme', | ||
themeData: ThemeData.light(), | ||
); | ||
SharedPreferencesAsyncPlatform.instance = | ||
InMemorySharedPreferencesAsync.empty(); | ||
|
||
await PlayxTheme.boot( | ||
config: PlayxThemeConfig( | ||
themes: [xTheme], | ||
)); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: PlayxThemeBuilder( | ||
child: Builder( | ||
builder: (context) { | ||
final retrievedTheme = XTheme.maybeOf(context); | ||
expect(retrievedTheme, xTheme); | ||
return Container(); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
|
||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: Builder( | ||
builder: (context) { | ||
final retrievedTheme = XTheme.maybeOf(context); | ||
expect(retrievedTheme, | ||
isNull); // No PlayxInheritedTheme in the context | ||
return Container(); | ||
}, | ||
), | ||
), | ||
); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.