mirror of
https://github.com/flutter/flutter.git
synced 2026-02-04 19:00:09 +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'), ), ], ), ), ); ```
15 lines
466 B
Dart
15 lines
466 B
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
void main() {
|
|
// Changes made in https://github.com/flutter/flutter/pull/145523
|
|
ButtonBar();
|
|
|
|
// Changes made in https://github.com/flutter/flutter/pull/145523
|
|
ThemeData theme = ThemeData();
|
|
theme = ThemeData(buttonBarTheme: ButtonBarThemeData());
|
|
}
|