mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

This adds a smoke test for every single API example. It also fixes 17 tests that had bugs in them, or were otherwise broken, and even fixes one actual bug in the framework, and one limitation in the framework. The bug in the framework is that NetworkImage's _loadAsync method had await response.drain<List<int>>();, but if the response is null, it will throw a cryptic exception saying that Null can't be assigned to List<int>. The fix was just to use await response.drain<void>(); instead. The limitation is that RelativePositionedTransition takes an Animation<Rect> rect parameter, and if you want to use a RectTween with it, the value emitted there is Rect?, and one of the examples was just casting from Animation<Rect> to Animation<Rect?>, which is invalid, so I modified RelativePositionedTransition to take a Rect? and just use Rect.zero if the rect is null.
91 lines
2.9 KiB
Dart
91 lines
2.9 KiB
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.
|
|
|
|
// Template: dev/snippets/config/templates/stateful_widget_scaffold_center_freeform_state.tmpl
|
|
//
|
|
// Comment lines marked with "▼▼▼" and "▲▲▲" are used for authoring
|
|
// of samples, and may be ignored if you are just exploring the sample.
|
|
|
|
// Flutter code sample for SlideTransition
|
|
//
|
|
//***************************************************************************
|
|
//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker)
|
|
|
|
// The following code implements the [SlideTransition] as seen in the video
|
|
// above:
|
|
|
|
//* ▲▲▲▲▲▲▲▲ description ▲▲▲▲▲▲▲▲ (do not modify or remove section marker)
|
|
//***************************************************************************
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
void main() => runApp(const MyApp());
|
|
|
|
/// This is the main application widget.
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
static const String _title = 'Flutter Code Sample';
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: _title,
|
|
home: Scaffold(
|
|
appBar: AppBar(title: const Text(_title)),
|
|
body: const Center(
|
|
child: MyStatefulWidget(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// This is the stateful widget that the main application instantiates.
|
|
class MyStatefulWidget extends StatefulWidget {
|
|
const MyStatefulWidget({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
|
|
}
|
|
|
|
/// This is the private State class that goes with MyStatefulWidget.
|
|
//********************************************************************
|
|
//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker)
|
|
|
|
class _MyStatefulWidgetState extends State<MyStatefulWidget>
|
|
with SingleTickerProviderStateMixin {
|
|
late final AnimationController _controller = AnimationController(
|
|
duration: const Duration(seconds: 2),
|
|
vsync: this,
|
|
)..repeat(reverse: true);
|
|
late final Animation<Offset> _offsetAnimation = Tween<Offset>(
|
|
begin: Offset.zero,
|
|
end: const Offset(1.5, 0.0),
|
|
).animate(CurvedAnimation(
|
|
parent: _controller,
|
|
curve: Curves.elasticIn,
|
|
));
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SlideTransition(
|
|
position: _offsetAnimation,
|
|
child: const Padding(
|
|
padding: EdgeInsets.all(8.0),
|
|
child: FlutterLogo(size: 150.0),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker)
|
|
//********************************************************************
|