add-content-resizing-sample
louisehsu 6 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'; 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
heightFactor: 1, child: Center(
child: Directionality( heightFactor: 1,
textDirection: TextDirection.ltr, child: Directionality(
child: Column( textDirection: TextDirection.ltr,
mainAxisAlignment: MainAxisAlignment.end, child: Column(
children: [ mainAxisSize: MainAxisSize.min,
for (int i = 0; i < _counter; i++) children: <Widget>[
Text( for (int i = 0; i < _listSize; i++)
"Hello from Flutter $i", Container(color: HSVColor.fromAHSV(1, (10.0 * i), 1, 1).toColor(), height: 50, width: 100),
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);
});
}

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

Loading…
Cancel
Save