Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Ensure the SmoothSimpleButton has a border on AMOLED theme #4440

Merged
merged 2 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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