snapshot of https://github.com/flutter/samples.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Main Branch CI / Test Flutter beta on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter stable on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter beta on macos-latest (push) Has been cancelled
Main Branch CI / Test Flutter stable on macos-latest (push) Has been cancelled

This commit is contained in:
upstream-mirror
2026-09-16 01:43:26 +05:00
commit 9ed6a80afa
2886 changed files with 140184 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
// Copyright 2023 The Flutter team. 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:animations/src/basics/basics.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Widget createAnimatedBuilderDemoScreen() =>
const MaterialApp(home: AnimatedBuilderDemo());
void main() {
group('AnimatedBuilder Tests', () {
testWidgets('AnimatedBuilder changes button color', (tester) async {
await tester.pumpWidget(createAnimatedBuilderDemoScreen());
// Get the initial color of the button.
ElevatedButton button = tester.widget(find.byType(ElevatedButton));
WidgetStateProperty<Color?>? initialColor =
button.style!.backgroundColor;
// Tap the button.
await tester.tap(find.byType(ElevatedButton));
await tester.pumpAndSettle();
// Get the updated color of the button.
button = tester.widget(find.byType(ElevatedButton));
WidgetStateProperty<Color?>? updatedColor =
button.style!.backgroundColor;
// Check if the color has changed.
expect(initialColor, isNot(updatedColor));
});
testWidgets('AnimatedBuilder animates button color', (tester) async {
await tester.pumpWidget(createAnimatedBuilderDemoScreen());
// Get the initial color of the button.
ElevatedButton button = tester.widget(find.byType(ElevatedButton));
WidgetStateProperty<Color?>? initialColor =
button.style!.backgroundColor;
// Tap the button to trigger the animation but don't wait for it to finish.
await tester.tap(find.byType(ElevatedButton));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
// Check that the color has changed but not to the final color.
button = tester.widget(find.byType(ElevatedButton));
WidgetStateProperty<Color?>? changedColor =
button.style!.backgroundColor;
expect(initialColor, isNot(changedColor));
// Wait for the animation to finish.
await tester.pump(const Duration(milliseconds: 400));
// Check that the color has changed to the final color.
button = tester.widget(find.byType(ElevatedButton));
WidgetStateProperty<Color?>? finalColor = button.style!.backgroundColor;
expect(changedColor, isNot(finalColor));
});
});
}

View File

@@ -0,0 +1,123 @@
// Copyright 2020 The Flutter team. 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:animations/src/misc/animated_list.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Widget createAnimatedListDemoScreen() =>
const MaterialApp(home: AnimatedListDemo());
void main() {
group('Animated List Tests', () {
testWidgets('Initial length of list', (tester) async {
await tester.pumpWidget(createAnimatedListDemoScreen());
// Get the initial length of list.
var initialLength = tester.widgetList(find.byType(ListTile)).length;
// Initial length of list should be equal to 5.
expect(initialLength, equals(5));
});
testWidgets('Length of list increases on Add Icon Button tap', (
tester,
) async {
await tester.pumpWidget(createAnimatedListDemoScreen());
// Get the initial length of list.
var initialLength = tester.widgetList(find.byType(ListTile)).length;
// Tap on the Add Icon Button.
await tester.tap(find.byIcon(Icons.add));
await tester.pumpAndSettle();
// Get the new length of list.
var newLength = tester.widgetList(find.byType(ListTile)).length;
// New length should be greater than initial length by one.
expect(newLength, equals(initialLength + 1));
});
testWidgets(
'Length of list decreases on Delete Icon Button tap at middle index',
(tester) async {
await tester.pumpWidget(createAnimatedListDemoScreen());
// Get the initial length of list.
var initialLength = tester.widgetList(find.byType(ListTile)).length;
// Tap on the Delete Icon Button at middle index.
await tester.tap(find.byIcon(Icons.delete).at(initialLength ~/ 2));
await tester.pumpAndSettle();
// Get the new length of list.
var newLength = tester.widgetList(find.byType(ListTile)).length;
// New length should be less than initial length by one.
expect(newLength, equals(initialLength - 1));
},
);
testWidgets(
'Length of list decreases on Delete Icon Button tap at start index',
(tester) async {
await tester.pumpWidget(createAnimatedListDemoScreen());
// Get the initial length of list.
var initialLength = tester.widgetList(find.byType(ListTile)).length;
// Tap on the Delete Icon Button at start index.
await tester.tap(find.byIcon(Icons.delete).at(0));
await tester.pumpAndSettle();
// Get the new length of list.
var newLength = tester.widgetList(find.byType(ListTile)).length;
// New length should be less than initial length by one.
expect(newLength, equals(initialLength - 1));
},
);
testWidgets(
'Length of list decreases on Delete Icon Button tap at end index',
(tester) async {
await tester.pumpWidget(createAnimatedListDemoScreen());
// Get the initial length of list.
var initialLength = tester.widgetList(find.byType(ListTile)).length;
// Tap on the Delete Icon Button at end index.
await tester.tap(find.byIcon(Icons.delete).at(initialLength - 1));
await tester.pumpAndSettle();
// Get the new length of list.
var newLength = tester.widgetList(find.byType(ListTile)).length;
// New Length should be less than initial length by one.
expect(newLength, equals(initialLength - 1));
},
);
testWidgets('All ListTiles deleted', (tester) async {
await tester.pumpWidget(createAnimatedListDemoScreen());
// Get the initial length of list.
var initialLength = tester.widgetList(find.byType(ListTile)).length;
// Iterating over all the Delete Icon Buttons.
for (var i = 0; i < initialLength; i++) {
// Tap on the Delete Icon
await tester.tap(find.byIcon(Icons.delete).first);
await tester.pumpAndSettle();
}
// Get the final length of list.
var finalLength = tester.widgetList(find.byType(ListTile)).length;
// New length should be zero.
expect(finalLength, equals(0));
});
});
}

View File

@@ -0,0 +1,32 @@
// Copyright 2020 The Flutter team. 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:animations/src/misc/animated_positioned.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Widget createAnimatedPositionedDemoScreen() =>
const MaterialApp(home: AnimatedPositionedDemo());
void main() {
group('AnimatedPositioned Tests', () {
testWidgets('Position of Button Changes on Tap', (tester) async {
await tester.pumpWidget(createAnimatedPositionedDemoScreen());
var button = find.byType(InkWell);
// Get initial position of the widget.
var initialPosition = tester.getTopLeft(button);
expect(initialPosition, isNotNull);
// Tap on the widget.
await tester.tap(button);
await tester.pumpAndSettle();
// The new position should not be equal to initial position.
var newPosition = tester.getTopLeft(button);
expect(newPosition, isNot(offsetMoreOrLessEquals(initialPosition)));
});
});
}

View File

@@ -0,0 +1,71 @@
// Copyright 2020 The Flutter team. 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:animations/src/misc/card_swipe.dart';
import 'package:flutter/material.dart' hide Card;
import 'package:flutter_test/flutter_test.dart';
Widget createCardSwipeScreen() => const MaterialApp(home: CardSwipeDemo());
void main() {
group('Card Swipe Tests', () {
testWidgets('One card swiped out', (tester) async {
await tester.pumpWidget(createCardSwipeScreen());
// Get the total number of cards available.
var totalCards = tester.widgetList(find.byType(Card)).length;
// Ensure card is visible.
await tester.ensureVisible(find.byType(Card).last);
// Swipe out one card.
await tester.drag(find.byType(Card).last, const Offset(100.0, 0.0));
await tester.pumpAndSettle();
// Check if removed properly.
expect(
tester.widgetList(find.byType(Card)).length,
lessThan(totalCards),
);
});
testWidgets('All cards swiped out', (tester) async {
await tester.pumpWidget(createCardSwipeScreen());
// Get the total number of cards availabe.
var totalCards = tester.widgetList(find.byType(Card)).length;
// Swipe out all cards.
for (var i = 0; i < totalCards; i++) {
// Swipe out one by one.
await tester.drag(
find.byType(Card).last,
const Offset(100.0, 0.0),
);
await tester.pumpAndSettle();
}
// Check if any card is remaining.
expect(find.byType(Card), findsNothing);
});
testWidgets('Stack refilled with cards', (tester) async {
await tester.pumpWidget(createCardSwipeScreen());
// Get the total number of cards availabe.
var totalCards = tester.widgetList(find.byType(Card)).length;
// Swipe out one card.
await tester.drag(find.byType(Card).last, const Offset(100.0, 0.0));
await tester.pumpAndSettle();
// Tap the Refill button.
await tester.tap(find.byType(ElevatedButton));
await tester.pumpAndSettle();
// Check if the entire stack is refilled.
expect(find.byType(Card), findsNWidgets(totalCards));
});
});
}

View File

@@ -0,0 +1,33 @@
// Copyright 2020 The Flutter team. 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:animations/src/misc/carousel.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Widget createCarouselDemoScreen() => MaterialApp(home: CarouselDemo());
void main() {
group('CarouselDemo tests', () {
testWidgets('Swipe left moves carousel', (tester) async {
await tester.pumpWidget(createCarouselDemoScreen());
// Get the images available on the screen during initial state.
var imageList = tester.widgetList(find.byType(Image)).toList();
expect(imageList.length, 2);
// Swipe the Carousel.
await tester.fling(
find.byType(CarouselDemo),
const Offset(-400, 0),
800,
);
await tester.pumpAndSettle();
// Get the images available on the screen after swipe.
imageList = tester.widgetList(find.byType(Image)).toList();
expect(imageList.length, 3);
});
});
}

View File

@@ -0,0 +1,47 @@
// Copyright 2020 The Flutter team. 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:animations/src/misc/expand_card.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Widget createExpandCardScreen() => const MaterialApp(home: ExpandCardDemo());
void main() {
group('ExpandCard Tests', () {
testWidgets('ExpandCard changes size on tap', (tester) async {
await tester.pumpWidget(createExpandCardScreen());
// Get the initial size of ExpandCard.
var initialSize = tester.getSize(find.byType(ExpandCard));
// Tap on the ExpandCard.
await tester.tap(find.byType(ExpandCard));
await tester.pumpAndSettle();
// The size of ExpandCard must change once tapped.
// The initialSize should be less than current ExpandCard size.
expect(
initialSize,
lessThan(tester.getSize(find.byType(ExpandCard))),
);
});
testWidgets('ExpandCard changes image on tap', (tester) async {
await tester.pumpWidget(createExpandCardScreen());
var initialImage = tester.widget(find.byType(Image).last);
// Tap on ExpandCard.
await tester.tap(find.byType(ExpandCard));
await tester.pumpAndSettle();
// Once tapped, the image should change.
expect(
initialImage,
isNot(equals(tester.widget(find.byType(Image).last))),
);
});
});
}

View File

@@ -0,0 +1,53 @@
// Copyright 2021 The Flutter team. 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:animations/src/misc/focus_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Widget createFocusImageScreen() => const MaterialApp(home: FocusImageDemo());
void main() {
group('FocusImage Tests', () {
testWidgets('Size of ink well changes on tap', (tester) async {
await tester.pumpWidget(createFocusImageScreen());
// Get the initial inkwell.
final initialInkwell = tester.widget(find.byType(InkWell).at(0));
// Get the size of initial inkwell.
var initialSize = tester.getSize(find.byWidget(initialInkwell));
// Tap on the ink well at index 0.
await tester.tap(find.byType(InkWell).at(0));
await tester.pumpAndSettle();
// Get the final inkwell.
final finalInkwell = tester.widget(find.byType(InkWell).at(0));
// Get the size of final inkwell.
var finalSize = tester.getSize(find.byWidget(finalInkwell));
// Final size should be greater than initial size.
expect(finalSize, greaterThan(initialSize));
});
testWidgets('Final inkwell on tap goes back to the grid', (
tester,
) async {
await tester.pumpWidget(createFocusImageScreen());
// Tap on the ink well at index 0.
await tester.tap(find.byType(InkWell).at(0));
await tester.pumpAndSettle();
// Tap on the final inkwell.
await tester.tap(find.byType(InkWell));
await tester.pumpAndSettle();
// The grid view should appear again.
expect(find.byType(Grid), findsOneWidget);
});
});
}

View File

@@ -0,0 +1,86 @@
// Copyright 2020 The Flutter team. 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:animations/src/misc/hero_animation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Widget createHeroAnimationDemoScreen() =>
const MaterialApp(home: HeroAnimationDemo());
void main() {
group('Hero Animation Tests', () {
testWidgets('Size of Container changes on Tap', (tester) async {
await tester.pumpWidget(createHeroAnimationDemoScreen());
// Get the initial Container.
var initialContainer = tester.firstWidget(find.byType(Container));
// Get the size of initial Container.
var initialSize = tester.getSize(find.byWidget(initialContainer));
// Tap on the Gesture Detector.
await tester.tap(find.byType(GestureDetector));
await tester.pumpAndSettle();
// Get the final Container.
var finalContainer = tester.firstWidget(find.byType(Container));
// Get the size of final Container.
var finalSize = tester.getSize(find.byWidget(finalContainer));
// initialSize should be less than finalSize.
expect(initialSize, lessThan(finalSize));
});
testWidgets('Color of Container changes on Tap', (tester) async {
await tester.pumpWidget(createHeroAnimationDemoScreen());
// Get the initial Container.
final initialContainer =
tester.firstWidget(find.byType(Container)) as Container;
// Initial color should be Color.grey[300].
expect(
(initialContainer.decoration as BoxDecoration).color,
Colors.grey[300],
);
// Tap on the GestureDetector.
await tester.tap(find.byType(GestureDetector));
await tester.pumpAndSettle();
// Get the final Container.
final finalContainer =
tester.firstWidget(find.byType(Container)) as Container;
// Final color should not be same as initial color.
expect(
(finalContainer.decoration as BoxDecoration).color,
isNot(
equals((initialContainer.decoration as BoxDecoration).color),
),
);
});
testWidgets('Screen Changes on Tap', (tester) async {
await tester.pumpWidget(createHeroAnimationDemoScreen());
// Get the initial Screen.
final initialScreen = tester.firstWidget(
find.byType(HeroAnimationDemo),
);
// Tap on the GestureDetector.
await tester.tap(find.byType(GestureDetector));
await tester.pumpAndSettle();
// Get the screen after navigation.
final finalScreen = tester.firstWidget(find.byType(HeroPage));
// initialScreen should not be same as finalScreen.
expect(initialScreen, isNot(equals(finalScreen)));
});
});
}

View File

@@ -0,0 +1,19 @@
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'package:animations/main.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('smoke test', (tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const AnimationSamples());
// Verify that a least one of our demos is showing up in the list
expect(find.text('AnimatedContainer'), findsOneWidget);
});
}