Skip to content

Commit

Permalink
chore(amplify_authenticator): remove support for amplify theme (#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan-Nelson committed Feb 17, 2022
1 parent a6e450a commit e127fee
Show file tree
Hide file tree
Showing 28 changed files with 62 additions and 1,214 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
93 changes: 0 additions & 93 deletions packages/amplify_authenticator/assets/Inter/OFL.txt

This file was deleted.

57 changes: 16 additions & 41 deletions packages/amplify_authenticator/lib/amplify_authenticator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import 'package:amplify_authenticator/src/state/inherited_authenticator_state.da
import 'package:amplify_authenticator/src/state/inherited_config.dart';
import 'package:amplify_authenticator/src/state/inherited_forms.dart';
import 'package:amplify_authenticator/src/state/inherited_strings.dart';
import 'package:amplify_authenticator/src/theme/amplify_theme.dart';
import 'package:amplify_authenticator/src/widgets/authenticator_banner.dart';
import 'package:amplify_authenticator/src/widgets/form.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
Expand Down Expand Up @@ -150,8 +149,6 @@ export 'src/widgets/form_field.dart'
/// ### Themeing
///
/// By default, the Authenticator uses your app's Material theme for its styling.
/// However, you can also use the a hand-crafted Amplify theme by setting
/// [useAmplifyTheme] to `true`.
///
/// ### Forms
///
Expand Down Expand Up @@ -286,7 +283,6 @@ class Authenticator extends StatefulWidget {
this.confirmSignInNewPasswordForm,
this.stringResolver = const AuthStringResolver(),
required this.child,
this.useAmplifyTheme = false,
this.onException,
this.exceptionBannerLocation = ExceptionBannerLocation.auto,
this.preferPrivateSession = false,
Expand Down Expand Up @@ -333,12 +329,6 @@ class Authenticator extends StatefulWidget {
return _AuthenticatorBody(child: child);
};

/// Whether to use Amplify colors and styles in the Authenticator,
/// instead of those defined by the app's Material [Theme].
///
/// Defaults to `false`.
final bool useAmplifyTheme;

// Padding around each authenticator view
final EdgeInsets padding;

Expand Down Expand Up @@ -424,8 +414,6 @@ class Authenticator extends StatefulWidget {
super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<AuthStringResolver>(
'stringResolver', stringResolver));
properties
.add(DiagnosticsProperty<bool>('useAmplifyTheme', useAmplifyTheme));
properties.add(
ObjectFlagProperty<ExceptionHandler?>.has('onException', onException));
properties.add(EnumProperty<ExceptionBannerLocation>(
Expand Down Expand Up @@ -526,7 +514,6 @@ class _AuthenticatorState extends State<Authenticator> {
..clearMaterialBanners()
..showMaterialBanner(createMaterialBanner(
scaffoldMessengerContext,
useAmplifyTheme: widget.useAmplifyTheme,
type: type,
content: content,
actions: [
Expand All @@ -543,7 +530,6 @@ class _AuthenticatorState extends State<Authenticator> {
scaffoldMessengerContext,
type: type,
content: content,
useAmplifyTheme: widget.useAmplifyTheme,
));
}
}
Expand Down Expand Up @@ -637,7 +623,6 @@ class _AuthenticatorState extends State<Authenticator> {
authBloc: _stateMachineBloc,
child: InheritedConfig(
amplifyConfig: _config,
useAmplifyTheme: widget.useAmplifyTheme,
padding: widget.padding,
child: InheritedAuthenticatorState(
key: keyInheritedAuthenticatorState,
Expand Down Expand Up @@ -717,31 +702,23 @@ class _AuthStateBuilder extends StatelessWidget {
Widget build(BuildContext context) {
final authenticatorBuilder = InheritedAuthenticatorBuilder.of(context);
final stateMachineBloc = InheritedAuthBloc.of(context);
final useAmplifyTheme = InheritedConfig.of(context).useAmplifyTheme;
final userAppTheme = Theme.of(context);
final bool isDark = AmplifyTheme.of(context).isDark;
return Theme(
data: useAmplifyTheme
? (isDark ? AmplifyTheme.dark : AmplifyTheme.light)
: userAppTheme,
child: StreamBuilder(
stream: stateMachineBloc.stream,
builder: (context, AsyncSnapshot<AuthState> snapshot) {
final authState = snapshot.data ?? const LoadingState();

final Widget authenticatorScreen = getAuthenticatorScreen(
context: context,
authenticatorBuilder: authenticatorBuilder,
authState: authState,
);
return StreamBuilder(
stream: stateMachineBloc.stream,
builder: (context, AsyncSnapshot<AuthState> snapshot) {
final authState = snapshot.data ?? const LoadingState();

final Widget authenticatorScreen = getAuthenticatorScreen(
context: context,
authenticatorBuilder: authenticatorBuilder,
authState: authState,
);

return Localizations.override(
context: context,
delegates: AuthenticatorLocalizations.localizationsDelegates,
child: builder(authState, authenticatorScreen),
);
},
),
return Localizations.override(
context: context,
delegates: AuthenticatorLocalizations.localizationsDelegates,
child: builder(authState, authenticatorScreen),
);
},
);
}

Expand Down Expand Up @@ -780,7 +757,6 @@ class _AuthenticatorBody extends StatelessWidget {
child: ScaffoldMessenger(
key: _AuthenticatorState.scaffoldMessengerKey,
child: Scaffold(
backgroundColor: AmplifyTheme.of(context).backgroundPrimary,
body: SizedBox.expand(
child: child is AuthenticatorScreen
? SingleChildScrollView(child: child)
Expand Down Expand Up @@ -821,7 +797,6 @@ class AuthenticatedView extends StatelessWidget {
return ScaffoldMessenger(
key: _AuthenticatorState.scaffoldMessengerKey,
child: Scaffold(
backgroundColor: AmplifyTheme.of(context).backgroundPrimary,
body: SizedBox.expand(
child: child is AuthenticatorScreen
? SingleChildScrollView(child: child)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* permissions and limitations under the License.
*/

import 'package:amplify_authenticator/src/state/inherited_config.dart';
import 'package:amplify_authenticator/src/theme/amplify_theme.dart';
import 'package:amplify_authenticator/src/widgets/form_field.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
Expand Down Expand Up @@ -44,7 +42,6 @@ mixin AuthenticatorDateField<FieldType,

@override
Widget buildFormField(BuildContext context) {
final useAmplifyTheme = InheritedConfig.of(context).useAmplifyTheme;
final inputResolver = stringResolver.inputs;
final hintText = widget.hintText == null
? inputResolver.resolve(context, widget.hintTextKey!)
Expand All @@ -69,7 +66,7 @@ mixin AuthenticatorDateField<FieldType,
style: enabled
? null
: TextStyle(
color: AmplifyTheme.of(context).fontDisabled,
color: Theme.of(context).disabledColor,
),
enabled: enabled,
readOnly: true,
Expand All @@ -82,7 +79,7 @@ mixin AuthenticatorDateField<FieldType,
onPressed: _pickTime,
),
errorMaxLines: errorMaxLines,
labelText: useAmplifyTheme ? null : labelText,
labelText: labelText,
hintText: hintText,
),
keyboardType: TextInputType.datetime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
* permissions and limitations under the License.
*/

import 'package:amplify_authenticator/src/state/inherited_config.dart';
import 'package:amplify_authenticator/src/theme/amplify_theme.dart';
import 'package:amplify_authenticator/src/widgets/form.dart';
import 'package:amplify_authenticator/src/widgets/form_field.dart';
import 'package:flutter/material.dart';
Expand All @@ -25,7 +23,6 @@ mixin AuthenticatorTextField<FieldType,
on AuthenticatorFormFieldState<FieldType, String, T> {
@override
Widget buildFormField(BuildContext context) {
final useAmplifyTheme = InheritedConfig.of(context).useAmplifyTheme;
final inputResolver = stringResolver.inputs;
final hintText = widget.hintText == null
? widget.hintTextKey?.resolve(context, inputResolver)
Expand All @@ -38,14 +35,14 @@ mixin AuthenticatorTextField<FieldType,
return TextFormField(
style: enabled
? null
: TextStyle(color: AmplifyTheme.of(context).fontDisabled),
: TextStyle(color: Theme.of(context).disabledColor),
initialValue: initialValue,
enabled: enabled,
validator: widget.validatorOverride ?? validator,
onChanged: onChanged,
autocorrect: false,
decoration: InputDecoration(
labelText: useAmplifyTheme ? null : labelText,
labelText: labelText,
prefixIcon: prefix,
prefixIconConstraints: const BoxConstraints(
minWidth: 40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import 'package:amplify_auth_cognito/amplify_auth_cognito.dart';
import 'package:amplify_authenticator/src/l10n/auth_strings_resolver.dart';
import 'package:amplify_authenticator/src/models/username_input.dart';
import 'package:amplify_authenticator/src/state/inherited_config.dart';
import 'package:amplify_authenticator/src/theme/amplify_theme.dart';
import 'package:amplify_authenticator/src/utils/validators.dart';
import 'package:amplify_authenticator/src/widgets/component.dart';
import 'package:amplify_authenticator/src/widgets/form_field.dart';
Expand Down Expand Up @@ -220,7 +218,6 @@ mixin AuthenticatorUsernameField<FieldType,

@override
Widget buildFormField(BuildContext context) {
final useAmplifyTheme = InheritedConfig.of(context).useAmplifyTheme;
final inputResolver = stringResolver.inputs;
final hintText = inputResolver.resolve(context, hintKey);

Expand Down Expand Up @@ -248,14 +245,13 @@ mixin AuthenticatorUsernameField<FieldType,
enabled: enabled,
errorMaxLines: errorMaxLines,
initialValue: state.getAttribute(CognitoUserAttributeKey.phoneNumber),
useAmplifyTheme: useAmplifyTheme,
);
}
return TextFormField(
style: enabled
? null
: TextStyle(
color: AmplifyTheme.of(context).fontDisabled,
color: Theme.of(context).disabledColor,
),
initialValue: initialValue?.username,
enabled: enabled,
Expand All @@ -266,7 +262,7 @@ mixin AuthenticatorUsernameField<FieldType,
prefixIcon: prefix,
suffixIcon: suffix,
errorMaxLines: errorMaxLines,
labelText: useAmplifyTheme ? null : labelText,
labelText: labelText,
hintText: hintText,
),
keyboardType: keyboardType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import 'package:amplify_authenticator/amplify_authenticator.dart';
import 'package:amplify_authenticator/src/constants/authenticator_constants.dart';
import 'package:amplify_authenticator/src/state/inherited_config.dart';
import 'package:amplify_authenticator/src/state/inherited_forms.dart';
import 'package:amplify_authenticator/src/theme/amplify_theme.dart';
import 'package:amplify_authenticator/src/widgets/component.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -99,10 +98,7 @@ class AuthenticatorScreen extends StatelessAuthenticatorComponent {

return Container(
constraints: BoxConstraints(maxWidth: containerWidth),
color: AmplifyTheme.of(context).backgroundPrimary,
child: SafeArea(
child: child,
),
child: SafeArea(child: child),
);
}

Expand Down Expand Up @@ -206,6 +202,14 @@ class _AuthenticatorTabViewState
setState(() {});
}

Color getTabLabelColor(BuildContext context) {
final bool isDark = Theme.of(context).brightness == Brightness.dark;
final labelColor = Theme.of(context).tabBarTheme.labelColor;
final textColor = Theme.of(context).textTheme.bodyText1?.color;
final fallbackColor = isDark ? Colors.white : Colors.black;
return labelColor ?? textColor ?? fallbackColor;
}

@override
Widget build(BuildContext context) {
return Column(
Expand All @@ -219,8 +223,7 @@ class _AuthenticatorTabViewState
text: stringResolver.buttons.resolve(context, tab.tabTitle),
),
],
labelColor: AmplifyTheme.of(context).tabLabelColor,
indicatorColor: AmplifyTheme.of(context).tabIndicatorColor,
labelColor: getTabLabelColor(context),
),
_FormWrapperView(step: selectedTab),
],
Expand Down
Loading

0 comments on commit e127fee

Please sign in to comment.