Revised Floating Action Button examples (#128058)
Of the original 4 examples, the first 3 mostly covered the same API features and occupied quite a bit of real-estate at the top of https://api.flutter.dev/flutter/material/FloatingActionButton-class.html. Additionally the illustrations and the code samples didn't match in some cases. Replaced examples 0,1,2 with one example that changes attributes of the FAB when it's pushed. Fixes https://github.com/flutter/flutter/issues/128048
This commit is contained in:
@@ -16,11 +16,30 @@ void main() {
|
||||
expect(find.byType(FloatingActionButton), findsOneWidget);
|
||||
expect(find.byIcon(Icons.navigation), findsOneWidget);
|
||||
|
||||
final Finder materialButtonFinder = find.byType(RawMaterialButton);
|
||||
RawMaterialButton getRawMaterialButtonWidget() {
|
||||
return tester.widget<RawMaterialButton>(materialButtonFinder);
|
||||
return tester.widget<RawMaterialButton>(find.byType(RawMaterialButton));
|
||||
}
|
||||
|
||||
Color? getIconColor() {
|
||||
final RichText iconRichText = tester.widget<RichText>(
|
||||
find.descendant(of: find.byIcon(Icons.navigation), matching: find.byType(RichText)),
|
||||
);
|
||||
return iconRichText.text.style?.color;
|
||||
}
|
||||
|
||||
await tester.tap(find.byType(FloatingActionButton));
|
||||
await tester.pumpAndSettle(); // Wait for the animation to finish.
|
||||
expect(getRawMaterialButtonWidget().fillColor, Colors.green);
|
||||
|
||||
await tester.tap(find.byType(FloatingActionButton));
|
||||
await tester.pumpAndSettle(); // Wait for the animation to finish.
|
||||
expect(getRawMaterialButtonWidget().fillColor, Colors.green);
|
||||
expect(getIconColor(), Colors.white);
|
||||
|
||||
await tester.tap(find.byType(FloatingActionButton));
|
||||
await tester.pumpAndSettle(); // Wait for the animation to finish.
|
||||
expect(getRawMaterialButtonWidget().fillColor, Colors.green);
|
||||
expect(getIconColor(), Colors.white);
|
||||
expect(getRawMaterialButtonWidget().shape, const CircleBorder());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,20 +8,42 @@ import 'package:flutter_api_samples/material/floating_action_button/floating_act
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('FloatingActionButton.extended', (WidgetTester tester) async {
|
||||
testWidgets('FloatingActionButton variants', (WidgetTester tester) async {
|
||||
RawMaterialButton getRawMaterialButtonWidget(Finder finder) {
|
||||
return tester.widget<RawMaterialButton>(finder);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.FloatingActionButtonExampleApp(),
|
||||
);
|
||||
|
||||
expect(find.byType(FloatingActionButton), findsOneWidget);
|
||||
expect(find.text('Approve'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.thumb_up), findsOneWidget);
|
||||
final ThemeData theme = ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true);
|
||||
|
||||
final Finder materialButtonFinder = find.byType(RawMaterialButton);
|
||||
RawMaterialButton getRawMaterialButtonWidget() {
|
||||
return tester.widget<RawMaterialButton>(materialButtonFinder);
|
||||
}
|
||||
expect(getRawMaterialButtonWidget().fillColor, Colors.pink);
|
||||
expect(getRawMaterialButtonWidget().shape, const StadiumBorder());
|
||||
expect(find.byType(FloatingActionButton), findsNWidgets(4));
|
||||
expect(find.byIcon(Icons.add), findsNWidgets(4));
|
||||
|
||||
final Finder smallFabMaterialButton = find.byType(RawMaterialButton).at(0);
|
||||
final RenderBox smallFabRenderBox = tester.renderObject(smallFabMaterialButton);
|
||||
expect(smallFabRenderBox.size, const Size(48.0, 48.0));
|
||||
expect(getRawMaterialButtonWidget(smallFabMaterialButton).fillColor, theme.colorScheme.primaryContainer);
|
||||
expect(getRawMaterialButtonWidget(smallFabMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)));
|
||||
|
||||
final Finder regularFABMaterialButton = find.byType(RawMaterialButton).at(1);
|
||||
final RenderBox regularFABRenderBox = tester.renderObject(regularFABMaterialButton);
|
||||
expect(regularFABRenderBox.size, const Size(56.0, 56.0));
|
||||
expect(getRawMaterialButtonWidget(regularFABMaterialButton).fillColor, theme.colorScheme.primaryContainer);
|
||||
expect(getRawMaterialButtonWidget(regularFABMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)));
|
||||
|
||||
final Finder largeFABMaterialButton = find.byType(RawMaterialButton).at(2);
|
||||
final RenderBox largeFABRenderBox = tester.renderObject(largeFABMaterialButton);
|
||||
expect(largeFABRenderBox.size, const Size(96.0, 96.0));
|
||||
expect(getRawMaterialButtonWidget(largeFABMaterialButton).fillColor, theme.colorScheme.primaryContainer);
|
||||
expect(getRawMaterialButtonWidget(largeFABMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(28.0)));
|
||||
|
||||
final Finder extendedFABMaterialButton = find.byType(RawMaterialButton).at(3);
|
||||
final RenderBox extendedFABRenderBox = tester.renderObject(extendedFABMaterialButton);
|
||||
expect(extendedFABRenderBox.size, const Size(111.0, 56.0));
|
||||
expect(getRawMaterialButtonWidget(extendedFABMaterialButton).fillColor, theme.colorScheme.primaryContainer);
|
||||
expect(getRawMaterialButtonWidget(extendedFABMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
// 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';
|
||||
import 'package:flutter_api_samples/material/floating_action_button/floating_action_button.2.dart'
|
||||
as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('FloatingActionButton - Material 3', (WidgetTester tester) async {
|
||||
RawMaterialButton getRawMaterialButtonWidget(Finder finder) {
|
||||
return tester.widget<RawMaterialButton>(finder);
|
||||
}
|
||||
await tester.pumpWidget(
|
||||
const example.FloatingActionButtonExampleApp(),
|
||||
);
|
||||
|
||||
expect(find.byType(FloatingActionButton), findsOneWidget);
|
||||
expect(find.byIcon(Icons.add), findsOneWidget);
|
||||
|
||||
final ThemeData theme = ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true);
|
||||
final Finder materialButtonFinder = find.byType(RawMaterialButton);
|
||||
expect(getRawMaterialButtonWidget(materialButtonFinder).fillColor, theme.colorScheme.primaryContainer);
|
||||
expect(getRawMaterialButtonWidget(materialButtonFinder).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)));
|
||||
});
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
// 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';
|
||||
import 'package:flutter_api_samples/material/floating_action_button/floating_action_button.3.dart'
|
||||
as example;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('FloatingActionButton variants', (WidgetTester tester) async {
|
||||
RawMaterialButton getRawMaterialButtonWidget(Finder finder) {
|
||||
return tester.widget<RawMaterialButton>(finder);
|
||||
}
|
||||
|
||||
await tester.pumpWidget(
|
||||
const example.FloatingActionButtonExampleApp(),
|
||||
);
|
||||
|
||||
final ThemeData theme = ThemeData(colorSchemeSeed: const Color(0xff6750a4), useMaterial3: true);
|
||||
|
||||
expect(find.byType(FloatingActionButton), findsNWidgets(4));
|
||||
expect(find.byIcon(Icons.add), findsNWidgets(4));
|
||||
|
||||
final Finder smallFabMaterialButton = find.byType(RawMaterialButton).at(0);
|
||||
final RenderBox smallFabRenderBox = tester.renderObject(smallFabMaterialButton);
|
||||
expect(smallFabRenderBox.size, const Size(48.0, 48.0));
|
||||
expect(getRawMaterialButtonWidget(smallFabMaterialButton).fillColor, theme.colorScheme.primaryContainer);
|
||||
expect(getRawMaterialButtonWidget(smallFabMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)));
|
||||
|
||||
final Finder regularFABMaterialButton = find.byType(RawMaterialButton).at(1);
|
||||
final RenderBox regularFABRenderBox = tester.renderObject(regularFABMaterialButton);
|
||||
expect(regularFABRenderBox.size, const Size(56.0, 56.0));
|
||||
expect(getRawMaterialButtonWidget(regularFABMaterialButton).fillColor, theme.colorScheme.primaryContainer);
|
||||
expect(getRawMaterialButtonWidget(regularFABMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)));
|
||||
|
||||
final Finder largeFABMaterialButton = find.byType(RawMaterialButton).at(2);
|
||||
final RenderBox largeFABRenderBox = tester.renderObject(largeFABMaterialButton);
|
||||
expect(largeFABRenderBox.size, const Size(96.0, 96.0));
|
||||
expect(getRawMaterialButtonWidget(largeFABMaterialButton).fillColor, theme.colorScheme.primaryContainer);
|
||||
expect(getRawMaterialButtonWidget(largeFABMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(28.0)));
|
||||
|
||||
final Finder extendedFABMaterialButton = find.byType(RawMaterialButton).at(3);
|
||||
final RenderBox extendedFABRenderBox = tester.renderObject(extendedFABMaterialButton);
|
||||
expect(extendedFABRenderBox.size, const Size(111.0, 56.0));
|
||||
expect(getRawMaterialButtonWidget(extendedFABMaterialButton).fillColor, theme.colorScheme.primaryContainer);
|
||||
expect(getRawMaterialButtonWidget(extendedFABMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user