mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This PR makes CupertinoTextField's placeholder and editable text position respect `CupertinoTextField.textAlignVertical`. <details open> <summary>Image comparison</summary> | | Before | After | | --- | --- | --- | | top | <img width="436" height="327" alt="top b4" src="https://github.com/user-attachments/assets/39606c72-fb1f-4619-bfb2-ccaeaf502324" /> | <img width="436" height="327" alt="top" src="https://github.com/user-attachments/assets/faea26fc-c934-4660-bbee-e62effa44599" /> | | center | <img width="436" height="327" alt="top b4" src="https://github.com/user-attachments/assets/39606c72-fb1f-4619-bfb2-ccaeaf502324" /> | <img width="436" height="327" alt="center" src="https://github.com/user-attachments/assets/2ee7004a-6f70-4af2-b33b-76293c8deac1" /> | | bottom | <img width="436" height="327" alt="top b4" src="https://github.com/user-attachments/assets/39606c72-fb1f-4619-bfb2-ccaeaf502324" /> | <img width="436" height="327" alt="bottom" src="https://github.com/user-attachments/assets/69ba89fb-9f1c-456e-9889-216eb31d66b9" /> | </details> <details> <summary>Sample code</summary> ```dart import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; void main() => runApp(const TextFieldApp()); class TextFieldApp extends StatelessWidget { const TextFieldApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp(home: HomePage()); } } class HomePage extends StatefulWidget { const HomePage({super.key}); @override State<HomePage> createState() => _HomePageState(); } class _HomePageState extends State<HomePage> { TextEditingController commentController = TextEditingController(); @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.grey, body: SafeArea( child: Center( child: Padding( padding: const EdgeInsets.all(8.0), child: CupertinoTextField( style: const TextStyle(fontSize: 40), placeholderStyle: const TextStyle( fontSize: 80, color: CupertinoColors.inactiveGray, ), placeholder: 'Enter text', textAlignVertical: TextAlignVertical.bottom, ), ), ), ), ); } } ``` </details> Fixes [CupertinoTextField text not vertically centered when fontSize differs between style and placeholderStyle.](https://github.com/flutter/flutter/issues/176817)