Skip to content

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 👍

}) : 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.

2 participants