Skip to content

Replace custom AccentOverride widget solution with theme styling solution #198

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

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
6 changes: 6 additions & 0 deletions mdc_100_series/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ ThemeData _buildShrineTheme() {
color: kShrineBrown900
),
inputDecorationTheme: InputDecorationTheme(
focusedBorder: CutCornersBorder(
borderSide: BorderSide(
width: 2.0,
color: kShrineBrown900,
),
),
border: CutCornersBorder(),
),
textTheme: _buildShrineTextTheme(base.textTheme),
Expand Down
76 changes: 40 additions & 36 deletions mdc_100_series/lib/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

import 'package:flutter/material.dart';

import 'colors.dart';

class LoginPage extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
Expand All @@ -24,6 +22,27 @@ class LoginPage extends StatefulWidget {
class _LoginPageState extends State<LoginPage> {
final _usernameController = TextEditingController();
final _passwordController = TextEditingController();
final _unfocusedColor = Colors.grey[600];
final _usernameFocusNode = FocusNode();
final _passwordFocusNode = FocusNode();

@override
void initState() {
super.initState();
_usernameFocusNode
..addListener(() {
setState(() {
//Redraw so that the username label reflects the focus state
});
});

_passwordFocusNode
..addListener(() {
setState(() {
//Redraw so that the password label reflects the focus state
});
});
}

@override
Widget build(BuildContext context) {
Expand All @@ -44,25 +63,29 @@ class _LoginPageState extends State<LoginPage> {
],
),
SizedBox(height: 120.0),
AccentColorOverride(
color: kShrineBrown900,
child: TextField(
controller: _usernameController,
decoration: InputDecoration(
labelText: 'Username',
),
TextField(
controller: _usernameController,
decoration: InputDecoration(
labelText: 'Username',
labelStyle: TextStyle(
color: _usernameFocusNode.hasFocus
? Theme.of(context).accentColor
: _unfocusedColor),
),
focusNode: _usernameFocusNode,
),
SizedBox(height: 12.0),
AccentColorOverride(
color: kShrineBrown900,
child: TextField(
controller: _passwordController,
decoration: InputDecoration(
labelText: 'Password',
),
obscureText: true,
TextField(
controller: _passwordController,
decoration: InputDecoration(
labelText: 'Password',
labelStyle: TextStyle(
color: _passwordFocusNode.hasFocus
? Theme.of(context).accentColor
: _unfocusedColor),
),
focusNode: _passwordFocusNode,
obscureText: true,
),
ButtonBar(
children: <Widget>[
Expand Down Expand Up @@ -94,22 +117,3 @@ class _LoginPageState extends State<LoginPage> {
);
}
}

class AccentColorOverride extends StatelessWidget {
const AccentColorOverride({Key key, this.color, this.child})
: super(key: key);

final Color color;
final Widget child;

@override
Widget build(BuildContext context) {
return Theme(
child: child,
data: Theme.of(context).copyWith(
accentColor: color,
brightness: Brightness.dark,
),
);
}
}