Skip to content

Commit

Permalink
feat: Ensure the SmoothSimpleButton has a border on AMOLED theme (#…
Browse files Browse the repository at this point in the history
…4440)

* Ensure the `SmoothSimpleButton` has a border

* Fix tests
  • Loading branch information
g123k authored Aug 5, 2023
1 parent 6fd6aa8 commit 390aa65
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/themes/theme_provider.dart';

class SmoothSimpleButton extends StatelessWidget {
const SmoothSimpleButton({
Expand Down Expand Up @@ -35,6 +37,18 @@ class SmoothSimpleButton extends StatelessWidget {
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(borderRadius: borderRadius),
),
overlayColor: context.read<ThemeProvider>().isAmoledTheme
? MaterialStateProperty.resolveWith((Set<MaterialState> states) {
return states.contains(MaterialState.pressed)
? Theme.of(context).colorScheme.primary.withOpacity(0.3)
: null;
})
: null,
side: context.read<ThemeProvider>().isAmoledTheme
? MaterialStateProperty.all<BorderSide>(
const BorderSide(color: Colors.white),
)
: null,
),
onPressed: onPressed,
child: Padding(
Expand Down
7 changes: 7 additions & 0 deletions packages/smooth_app/lib/themes/theme_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ThemeProvider with ChangeNotifier {
ThemeProvider(this._userPreferences);

final UserPreferences _userPreferences;

// The onboarding needs the light mode.
bool _forceLight = false;

Expand All @@ -20,6 +21,12 @@ class ThemeProvider with ChangeNotifier {
_forceLight = !onboardingComplete;
}

bool get isLightTheme => _forceLight || currentTheme == THEME_LIGHT;

bool get isDarkTheme => !_forceLight && currentTheme == THEME_DARK;

bool get isAmoledTheme => !_forceLight && currentTheme == THEME_AMOLED;

void finishOnboarding() {
setOnboardingComplete(true);
notifyListeners();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/generic_lib/buttons/smooth_simple_button.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_error_card.dart';
import 'package:smooth_app/themes/theme_provider.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

import '../../../tests_utils/mocks.dart';

void main() {
const String errorMessageTest = 'error message test';
const String smoothErrorCardTitle = 'There was an error';
Expand Down Expand Up @@ -40,15 +46,24 @@ void main() {
tryAgainFunctionTest = () {};
});

Future<void> pumpSmoothErrorCardOnScreen(WidgetTester tester) {
Future<void> pumpSmoothErrorCardOnScreen(WidgetTester tester) async {
SharedPreferences.setMockInitialValues(
mockSharedPreferences(),
);

final UserPreferences prefs = await UserPreferences.getUserPreferences();

return tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
locale: const Locale('en'),
home: SmoothScaffold(
body: SmoothErrorCard(
errorMessage: errorMessageTest,
tryAgainFunction: tryAgainFunctionTest,
ChangeNotifierProvider<ThemeProvider>(
create: (_) => ThemeProvider(prefs),
child: MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
locale: const Locale('en'),
home: SmoothScaffold(
body: SmoothErrorCard(
errorMessage: errorMessageTest,
tryAgainFunction: tryAgainFunctionTest,
),
),
),
),
Expand Down

0 comments on commit 390aa65

Please sign in to comment.