mirror of https://github.com/flutter/samples.git
parent
872d491267
commit
10aa6f746d
@ -1,55 +1,46 @@
|
|||||||
|
// 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/material.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const ResizeApp());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The main application widget for the Fruit Catalog.
|
class ResizeApp extends StatefulWidget {
|
||||||
class MyApp extends StatefulWidget {
|
/// Creates the [ResizeApp].
|
||||||
/// Creates the [MyApp].
|
const ResizeApp({super.key});
|
||||||
const MyApp({super.key});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MyApp> createState() => _MyAppState();
|
State<ResizeApp> createState() => _ResizeAppState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MyAppState extends State<MyApp> {
|
class _ResizeAppState extends State<ResizeApp> {
|
||||||
int _counter = 1;
|
int _listSize = 1;
|
||||||
void _incrementCounter() {
|
void _addToList() {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (_counter > 40) {
|
_listSize++;
|
||||||
_counter = 1;
|
|
||||||
}
|
|
||||||
_counter++;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
return Center(
|
onTap: _addToList, // The tap anywhere logic
|
||||||
|
child: Center(
|
||||||
heightFactor: 1,
|
heightFactor: 1,
|
||||||
child: Directionality(
|
child: Directionality(
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: <Widget>[
|
||||||
for (int i = 0; i < _counter; i++)
|
for (int i = 0; i < _listSize; i++)
|
||||||
Text(
|
Container(color: HSVColor.fromAHSV(1, (10.0 * i), 1, 1).toColor(), height: 50, width: 100),
|
||||||
"Hello from Flutter $i",
|
|
||||||
style: TextStyle(color: Colors.pink),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.fromLTRB(8.0, 50, 8.0, 8.0),
|
|
||||||
child: ElevatedButton(
|
|
||||||
onPressed: _incrementCounter,
|
|
||||||
child: Text("Add to list"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,30 +0,0 @@
|
|||||||
// This is a basic Flutter widget test.
|
|
||||||
//
|
|
||||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
|
||||||
// utility in the flutter_test package. 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:flutter/material.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
|
|
||||||
import 'package:flutter_module/main.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
|
||||||
// Build our app and trigger a frame.
|
|
||||||
await tester.pumpWidget(const MyApp());
|
|
||||||
|
|
||||||
// Verify that our counter starts at 0.
|
|
||||||
expect(find.text('0'), findsOneWidget);
|
|
||||||
expect(find.text('1'), findsNothing);
|
|
||||||
|
|
||||||
// Tap the '+' icon and trigger a frame.
|
|
||||||
await tester.tap(find.byIcon(Icons.add));
|
|
||||||
await tester.pump();
|
|
||||||
|
|
||||||
// Verify that our counter has incremented.
|
|
||||||
expect(find.text('0'), findsNothing);
|
|
||||||
expect(find.text('1'), findsOneWidget);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Binary file not shown.
Loading…
Reference in new issue