mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Flutter 3.29 beta (#2571)
This commit is contained in:
@@ -53,9 +53,7 @@ class DataTransferPage extends StatelessWidget {
|
||||
value: controller.progressPercent,
|
||||
backgroundColor: Colors.grey[200],
|
||||
),
|
||||
const Expanded(
|
||||
child: RunningList(),
|
||||
),
|
||||
const Expanded(child: RunningList()),
|
||||
Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
@@ -116,7 +114,9 @@ class DataTransferIsolateController extends ChangeNotifier {
|
||||
Future<void> createIsolate() async {
|
||||
_incomingReceivePort = ReceivePort();
|
||||
_isolate = await Isolate.spawn(
|
||||
_secondIsolateEntryPoint, _incomingReceivePort.sendPort);
|
||||
_secondIsolateEntryPoint,
|
||||
_incomingReceivePort.sendPort,
|
||||
);
|
||||
}
|
||||
|
||||
void listen() {
|
||||
@@ -126,7 +126,9 @@ class DataTransferIsolateController extends ChangeNotifier {
|
||||
_outgoingSendPort = message;
|
||||
case int():
|
||||
currentProgress.insert(
|
||||
0, '$message% - ${_timer.elapsedMilliseconds / 1000} seconds');
|
||||
0,
|
||||
'$message% - ${_timer.elapsedMilliseconds / 1000} seconds',
|
||||
);
|
||||
progressPercent = message / 100;
|
||||
case 'done':
|
||||
runningTest = 0;
|
||||
@@ -176,8 +178,9 @@ class DataTransferIsolateController extends ChangeNotifier {
|
||||
}
|
||||
|
||||
if (transferableTyped) {
|
||||
final transferable =
|
||||
TransferableTypedData.fromList([Int32List.fromList(randNums)]);
|
||||
final transferable = TransferableTypedData.fromList([
|
||||
Int32List.fromList(randNums),
|
||||
]);
|
||||
await sendNumbers(transferable);
|
||||
} else {
|
||||
await sendNumbers(randNums);
|
||||
@@ -208,9 +211,7 @@ class RunningList extends StatelessWidget {
|
||||
Provider.of<DataTransferIsolateController>(context).currentProgress;
|
||||
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[200],
|
||||
),
|
||||
decoration: BoxDecoration(color: Colors.grey[200]),
|
||||
child: ListView.builder(
|
||||
itemCount: progress.length,
|
||||
itemBuilder: (context, index) {
|
||||
@@ -218,14 +219,9 @@ class RunningList extends StatelessWidget {
|
||||
children: [
|
||||
Card(
|
||||
color: Colors.lightGreenAccent,
|
||||
child: ListTile(
|
||||
title: Text(progress[index]),
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
color: Colors.blue,
|
||||
height: 3,
|
||||
child: ListTile(title: Text(progress[index])),
|
||||
),
|
||||
const Divider(color: Colors.blue, height: 3),
|
||||
],
|
||||
);
|
||||
},
|
||||
@@ -239,27 +235,28 @@ Future<void> _secondIsolateEntryPoint(SendPort sendPort) async {
|
||||
sendPort.send(receivePort.sendPort);
|
||||
var length = 1;
|
||||
|
||||
receivePort.listen(
|
||||
(dynamic message) async {
|
||||
if (message is String && message == 'start') {
|
||||
await generateAndSum(sendPort, createNums(), length);
|
||||
receivePort.listen((dynamic message) async {
|
||||
if (message is String && message == 'start') {
|
||||
await generateAndSum(sendPort, createNums(), length);
|
||||
|
||||
sendPort.send('done');
|
||||
} else if (message is TransferableTypedData) {
|
||||
await generateAndSum(
|
||||
sendPort, message.materialize().asInt32List(), length);
|
||||
length++;
|
||||
} else if (message is List<int>) {
|
||||
await generateAndSum(sendPort, message, length);
|
||||
length++;
|
||||
}
|
||||
sendPort.send('done');
|
||||
} else if (message is TransferableTypedData) {
|
||||
await generateAndSum(
|
||||
sendPort,
|
||||
message.materialize().asInt32List(),
|
||||
length,
|
||||
);
|
||||
length++;
|
||||
} else if (message is List<int>) {
|
||||
await generateAndSum(sendPort, message, length);
|
||||
length++;
|
||||
}
|
||||
|
||||
if (length == 101) {
|
||||
sendPort.send('done');
|
||||
length = 1;
|
||||
}
|
||||
},
|
||||
);
|
||||
if (length == 101) {
|
||||
sendPort.send('done');
|
||||
length = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Iterable<int> createNums() sync* {
|
||||
|
||||
@@ -48,9 +48,7 @@ class InfiniteProcessPage extends StatelessWidget {
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
),
|
||||
const Expanded(
|
||||
child: RunningList(),
|
||||
),
|
||||
const Expanded(child: RunningList()),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -96,7 +94,7 @@ class InfiniteProcessPage extends StatelessWidget {
|
||||
groupValue: controller.currentMultiplier,
|
||||
onChanged: (val) => controller.setMultiplier(val!),
|
||||
),
|
||||
Text('${i}x')
|
||||
Text('${i}x'),
|
||||
],
|
||||
],
|
||||
),
|
||||
@@ -129,8 +127,10 @@ class InfiniteProcessIsolateController extends ChangeNotifier {
|
||||
|
||||
Future<void> createIsolate() async {
|
||||
receivePort = ReceivePort();
|
||||
newIsolate =
|
||||
await Isolate.spawn(_secondIsolateEntryPoint, receivePort.sendPort);
|
||||
newIsolate = await Isolate.spawn(
|
||||
_secondIsolateEntryPoint,
|
||||
receivePort.sendPort,
|
||||
);
|
||||
}
|
||||
|
||||
void listen() {
|
||||
@@ -201,27 +201,23 @@ class RunningList extends StatelessWidget {
|
||||
var sums = controller.currentResults;
|
||||
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[200],
|
||||
),
|
||||
decoration: BoxDecoration(color: Colors.grey[200]),
|
||||
child: ListView.builder(
|
||||
itemCount: sums.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Column(
|
||||
children: [
|
||||
Card(
|
||||
color: (controller.created && !controller.paused)
|
||||
? Colors.lightGreenAccent
|
||||
: Colors.deepOrangeAccent,
|
||||
color:
|
||||
(controller.created && !controller.paused)
|
||||
? Colors.lightGreenAccent
|
||||
: Colors.deepOrangeAccent,
|
||||
child: ListTile(
|
||||
leading: Text('${sums.length - index}.'),
|
||||
title: Text('${sums[index]}.'),
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
color: Colors.blue,
|
||||
height: 3,
|
||||
),
|
||||
const Divider(color: Colors.blue, height: 3),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
@@ -24,11 +24,7 @@ import 'performance_page.dart';
|
||||
|
||||
void main() {
|
||||
setupWindow();
|
||||
runApp(
|
||||
const MaterialApp(
|
||||
home: HomePage(),
|
||||
),
|
||||
);
|
||||
runApp(const MaterialApp(home: HomePage()));
|
||||
}
|
||||
|
||||
const double windowWidth = 1024;
|
||||
@@ -55,18 +51,9 @@ class HomePage extends StatelessWidget {
|
||||
appBar: AppBar(
|
||||
bottom: const TabBar(
|
||||
tabs: [
|
||||
Tab(
|
||||
icon: Icon(Icons.flash_on),
|
||||
text: 'Performance',
|
||||
),
|
||||
Tab(
|
||||
icon: Icon(Icons.sync),
|
||||
text: 'Infinite Process',
|
||||
),
|
||||
Tab(
|
||||
icon: Icon(Icons.storage),
|
||||
text: 'Data Transfer',
|
||||
),
|
||||
Tab(icon: Icon(Icons.flash_on), text: 'Performance'),
|
||||
Tab(icon: Icon(Icons.sync), text: 'Infinite Process'),
|
||||
Tab(icon: Icon(Icons.storage), text: 'Data Transfer'),
|
||||
],
|
||||
),
|
||||
title: const Text('Isolate Example'),
|
||||
|
||||
@@ -57,9 +57,9 @@ class _PerformancePageState extends State<PerformancePage> {
|
||||
return ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(elevation: 8.0),
|
||||
onPressed: switch (snapshot.connectionState) {
|
||||
ConnectionState.done => () =>
|
||||
handleComputeOnMain(context),
|
||||
_ => null
|
||||
ConnectionState.done =>
|
||||
() => handleComputeOnMain(context),
|
||||
_ => null,
|
||||
},
|
||||
child: const Text('Compute on Main'),
|
||||
);
|
||||
@@ -69,13 +69,14 @@ class _PerformancePageState extends State<PerformancePage> {
|
||||
future: computeFuture,
|
||||
builder: (context, snapshot) {
|
||||
return ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(elevation: 8.0),
|
||||
onPressed: switch (snapshot.connectionState) {
|
||||
ConnectionState.done => () =>
|
||||
handleComputeOnSecondary(context),
|
||||
_ => null
|
||||
},
|
||||
child: const Text('Compute on Secondary'));
|
||||
style: ElevatedButton.styleFrom(elevation: 8.0),
|
||||
onPressed: switch (snapshot.connectionState) {
|
||||
ConnectionState.done =>
|
||||
() => handleComputeOnSecondary(context),
|
||||
_ => null,
|
||||
},
|
||||
child: const Text('Compute on Secondary'),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
@@ -87,14 +88,12 @@ class _PerformancePageState extends State<PerformancePage> {
|
||||
}
|
||||
|
||||
void handleComputeOnMain(BuildContext context) {
|
||||
var future = computeOnMainIsolate()
|
||||
..then((_) {
|
||||
var snackBar = const SnackBar(
|
||||
content: Text('Main Isolate Done!'),
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
});
|
||||
var future =
|
||||
computeOnMainIsolate()..then((_) {
|
||||
var snackBar = const SnackBar(content: Text('Main Isolate Done!'));
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
});
|
||||
|
||||
setState(() {
|
||||
computeFuture = future;
|
||||
@@ -102,14 +101,14 @@ class _PerformancePageState extends State<PerformancePage> {
|
||||
}
|
||||
|
||||
void handleComputeOnSecondary(BuildContext context) {
|
||||
var future = computeOnSecondaryIsolate()
|
||||
..then((_) {
|
||||
var snackBar = const SnackBar(
|
||||
content: Text('Secondary Isolate Done!'),
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
});
|
||||
var future =
|
||||
computeOnSecondaryIsolate()..then((_) {
|
||||
var snackBar = const SnackBar(
|
||||
content: Text('Secondary Isolate Done!'),
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
});
|
||||
|
||||
setState(() {
|
||||
computeFuture = future;
|
||||
@@ -146,13 +145,15 @@ class _SmoothAnimationWidgetState extends State<SmoothAnimationWidget>
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_animationController =
|
||||
AnimationController(duration: const Duration(seconds: 1), vsync: this);
|
||||
_animationController = AnimationController(
|
||||
duration: const Duration(seconds: 1),
|
||||
vsync: this,
|
||||
);
|
||||
|
||||
_borderAnimation = BorderRadiusTween(
|
||||
begin: BorderRadius.circular(100.0),
|
||||
end: BorderRadius.circular(0.0))
|
||||
.animate(_animationController);
|
||||
begin: BorderRadius.circular(100.0),
|
||||
end: BorderRadius.circular(0.0),
|
||||
).animate(_animationController);
|
||||
|
||||
_animationController.repeat(reverse: true);
|
||||
}
|
||||
@@ -170,16 +171,11 @@ class _SmoothAnimationWidgetState extends State<SmoothAnimationWidget>
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
colors: [
|
||||
Colors.blueAccent,
|
||||
Colors.redAccent,
|
||||
],
|
||||
colors: [Colors.blueAccent, Colors.redAccent],
|
||||
),
|
||||
borderRadius: _borderAnimation.value,
|
||||
),
|
||||
child: const FlutterLogo(
|
||||
size: 200,
|
||||
),
|
||||
child: const FlutterLogo(size: 200),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -4,7 +4,7 @@ version: 1.0.0+1
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: ^3.5.0
|
||||
sdk: ^3.7.0-0
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
|
||||
Reference in New Issue
Block a user