Skip to content

Added CupertinoButton alignment property - #73900

Merged
HansMuller merged 2 commits into
flutter:masterfrom
HansMuller:cupertino_button_child_alignment
Jan 14, 2021
Merged

HansMuller merged 2 commits into
flutter:masterfrom
HansMuller:cupertino_button_child_alignment

Conversation

@HansMuller

Copy link
Copy Markdown
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 p: cupertino_ui cupertino_ui package in flutter/packages 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

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 👍

}) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)),
assert(disabledColor != null),
assert(disabledColor != null),
assert(alignment != null),

Copy link
Copy Markdown
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
Copy Markdown
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

framework flutter/packages/flutter repository. See also f: labels. p: cupertino_ui cupertino_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants