add-content-resizing-sample
louisehsu 5 days ago
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';
void main() {
runApp(const MyApp());
runApp(const ResizeApp());
}
/// The main application widget for the Fruit Catalog.
class MyApp extends StatefulWidget {
/// Creates the [MyApp].
const MyApp({super.key});
class ResizeApp extends StatefulWidget {
/// Creates the [ResizeApp].
const ResizeApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
State<ResizeApp> createState() => _ResizeAppState();
}
class _MyAppState extends State<MyApp> {
int _counter = 1;
void _incrementCounter() {
class _ResizeAppState extends State<ResizeApp> {
int _listSize = 1;
void _addToList() {
setState(() {
if (_counter > 40) {
_counter = 1;
}
_counter++;
_listSize++;
});
}
@override
Widget build(BuildContext context) {
return Center(
heightFactor: 1,
child: Directionality(
textDirection: TextDirection.ltr,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
for (int i = 0; i < _counter; i++)
Text(
"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"),
),
),
],
return GestureDetector(
onTap: _addToList, // The tap anywhere logic
child: Center(
heightFactor: 1,
child: Directionality(
textDirection: TextDirection.ltr,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
for (int i = 0; i < _listSize; i++)
Container(color: HSVColor.fromAHSV(1, (10.0 * i), 1, 1).toColor(), height: 50, width: 100),
],
),
),
),
);
}
}
}

@ -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);
});
}

@ -15,6 +15,7 @@ class ViewController: UIViewController {
let stackView = UIStackView()
stackView.axis = .vertical
stackView.distribution = .fill
stackView.backgroundColor = .yellow
stackView.translatesAutoresizingMaskIntoConstraints = false
let engine1 = FlutterEngine(name: "one")
@ -27,6 +28,7 @@ class ViewController: UIViewController {
addChild(flutterViewController)
stackView.addArrangedSubview(flutterViewController.view)
flutterViewController.didMove(toParent: self)
} else {
let label = UILabel()
label.text = "Hello from iOS \(index)"

Loading…
Cancel
Save