mirror of
https://github.com/flutter/flutter.git
synced 2026-01-21 05:04:42 +08:00
fixes [Deprecate `ButtonBar`](https://github.com/flutter/flutter/issues/127955) ### Code sample <details> <summary>expand to view the code sample</summary> ```dart import 'package:flutter/material.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( theme: ThemeData( buttonBarTheme: const ButtonBarThemeData( alignment: MainAxisAlignment.spaceEvenly, ), ), home: Scaffold( body: ButtonBar( alignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ TextButton( onPressed: () {}, child: const Text('Button 1'), ), TextButton( onPressed: () {}, child: const Text('Button 2'), ), TextButton( onPressed: () {}, child: const Text('Button 3'), ), ], ), ), ); } } ``` </details> ## Data driven fix ### Before executing `dart fix --apply` ```dart return MaterialApp( theme: ThemeData( buttonBarTheme: const ButtonBarThemeData( alignment: MainAxisAlignment.spaceEvenly, ), ), home: Scaffold( body: ButtonBar( alignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ TextButton( onPressed: () {}, child: const Text('Button 1'), ), TextButton( onPressed: () {}, child: const Text('Button 2'), ), TextButton( onPressed: () {}, child: const Text('Button 3'), ), ], ), ), ); ``` ### After executing `dart fix --apply` ```dart return MaterialApp( theme: ThemeData( ), home: Scaffold( body: OverflowBar( alignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ TextButton( onPressed: () {}, child: const Text('Button 1'), ), TextButton( onPressed: () {}, child: const Text('Button 2'), ), TextButton( onPressed: () {}, child: const Text('Button 3'), ), ], ), ), ); ```