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.
114 lines
3.4 KiB
Dart
114 lines
3.4 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/stateless_widget_scaffold_center.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 Hero
|
|
//
|
|
//***************************************************************************
|
|
//* ▼▼▼▼▼▼▼▼ description ▼▼▼▼▼▼▼▼ (do not modify or remove section marker)
|
|
|
|
// This sample shows a [Hero] used within a [ListTile].
|
|
//
|
|
// Tapping on the Hero-wrapped rectangle triggers a hero
|
|
// animation as a new [MaterialPageRoute] is pushed. Both the size
|
|
// and location of the rectangle animates.
|
|
//
|
|
// Both widgets use the same [Hero.tag].
|
|
//
|
|
// The Hero widget uses the matching tags to identify and execute this
|
|
// animation.
|
|
|
|
//* ▲▲▲▲▲▲▲▲ 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: MyStatelessWidget(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// This is the stateless widget that the main application instantiates.
|
|
class MyStatelessWidget extends StatelessWidget {
|
|
const MyStatelessWidget({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
//********************************************************************
|
|
//* ▼▼▼▼▼▼▼▼ code ▼▼▼▼▼▼▼▼ (do not modify or remove section marker)
|
|
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: <Widget>[
|
|
const SizedBox(
|
|
height: 20.0,
|
|
),
|
|
ListTile(
|
|
leading: Hero(
|
|
tag: 'hero-rectangle',
|
|
child: _blueRectangle(const Size(50, 50)),
|
|
),
|
|
onTap: () => _gotoDetailsPage(context),
|
|
title:
|
|
const Text('Tap on the icon to view hero animation transition.'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _blueRectangle(Size size) {
|
|
return Container(
|
|
width: size.width,
|
|
height: size.height,
|
|
color: Colors.blue,
|
|
);
|
|
}
|
|
|
|
void _gotoDetailsPage(BuildContext context) {
|
|
Navigator.of(context).push(MaterialPageRoute<void>(
|
|
builder: (BuildContext context) => Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('second Page'),
|
|
),
|
|
body: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
Hero(
|
|
tag: 'hero-rectangle',
|
|
child: _blueRectangle(const Size(200, 200)),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
));
|
|
}
|
|
|
|
//* ▲▲▲▲▲▲▲▲ code ▲▲▲▲▲▲▲▲ (do not modify or remove section marker)
|
|
//********************************************************************
|
|
|
|
}
|