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

Added CupertinoButton alignment property #73900

Merged

Conversation

HansMuller
Copy link
Contributor

Added an AlignmentGeometry valued alignment property to CupertinoButton which defines how the button's child is aligned within the available space. This generally only applies with the button size is constrained to have a different size than it would have by default.

The following example constrains the width of 3 buttons to be 300. Their alignment parameter is center (same as the default), centerRight, and centerLeft.

Screen Shot 2021-01-13 at 2 24 46 PM

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
      child: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            SizedBox(
              width: 300,
              child: CupertinoButton.filled(
                alignment: Alignment.center,
                padding: EdgeInsets.all(16),
                onPressed: () { },
                child: Text('center'),
              ),
            ),
            SizedBox(height: 16),
            SizedBox(
              width: 300,
              child: CupertinoButton.filled(
                alignment: Alignment.centerRight,
                padding: EdgeInsets.all(16),
                onPressed: () { },
                child: Text('centerRight'),
              ),
            ),
            SizedBox(height: 16),
            SizedBox(
              width: 300,
              child: CupertinoButton.filled(
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.all(16),
                onPressed: () { },
                child: Text('centerLeft'),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

void main() {
  runApp(CupertinoApp(home: Home()));
}

@flutter-dashboard flutter-dashboard bot added f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels. labels Jan 13, 2021
@google-cla google-cla bot added the cla: yes label Jan 13, 2021
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

required this.onPressed,
}) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)),
assert(disabledColor != null),
assert(disabledColor != null),
assert(alignment != null),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this indentation correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, fixed that.

@HansMuller HansMuller merged commit f557825 into flutter:master Jan 14, 2021
@HansMuller HansMuller deleted the cupertino_button_child_alignment branch January 14, 2021 00:29
@justinmc justinmc mentioned this pull request Jan 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants