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:
@@ -28,11 +28,13 @@ void setupWindow() {
|
||||
setWindowMinSize(const Size(windowWidth, windowHeight));
|
||||
setWindowMaxSize(const Size(windowWidth, windowHeight));
|
||||
getCurrentScreen().then((screen) {
|
||||
setWindowFrame(Rect.fromCenter(
|
||||
center: screen!.frame.center,
|
||||
width: windowWidth,
|
||||
height: windowHeight,
|
||||
));
|
||||
setWindowFrame(
|
||||
Rect.fromCenter(
|
||||
center: screen!.frame.center,
|
||||
width: windowWidth,
|
||||
height: windowHeight,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -59,34 +61,33 @@ class MyHomePage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Infinite List Sample'),
|
||||
),
|
||||
appBar: AppBar(title: const Text('Infinite List Sample')),
|
||||
body: Selector<Catalog, int?>(
|
||||
// Selector is a widget from package:provider. It allows us to listen
|
||||
// to only one aspect of a provided value. In this case, we are only
|
||||
// listening to the catalog's `itemCount`, because that's all we need
|
||||
// at this level.
|
||||
selector: (context, catalog) => catalog.itemCount,
|
||||
builder: (context, itemCount, child) => ListView.builder(
|
||||
// When `itemCount` is null, `ListView` assumes an infinite list.
|
||||
// Once we provide a value, it will stop the scrolling beyond
|
||||
// the last element.
|
||||
itemCount: itemCount,
|
||||
padding: const EdgeInsets.symmetric(vertical: 18),
|
||||
itemBuilder: (context, index) {
|
||||
// Every item of the `ListView` is individually listening
|
||||
// to the catalog.
|
||||
var catalog = Provider.of<Catalog>(context);
|
||||
builder:
|
||||
(context, itemCount, child) => ListView.builder(
|
||||
// When `itemCount` is null, `ListView` assumes an infinite list.
|
||||
// Once we provide a value, it will stop the scrolling beyond
|
||||
// the last element.
|
||||
itemCount: itemCount,
|
||||
padding: const EdgeInsets.symmetric(vertical: 18),
|
||||
itemBuilder: (context, index) {
|
||||
// Every item of the `ListView` is individually listening
|
||||
// to the catalog.
|
||||
var catalog = Provider.of<Catalog>(context);
|
||||
|
||||
// Catalog provides a single synchronous method for getting the
|
||||
// current data.
|
||||
return switch (catalog.getByIndex(index)) {
|
||||
Item(isLoading: true) => const LoadingItemTile(),
|
||||
var item => ItemTile(item: item)
|
||||
};
|
||||
},
|
||||
),
|
||||
// Catalog provides a single synchronous method for getting the
|
||||
// current data.
|
||||
return switch (catalog.getByIndex(index)) {
|
||||
Item(isLoading: true) => const LoadingItemTile(),
|
||||
var item => ItemTile(item: item),
|
||||
};
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -21,22 +21,19 @@ Future<ItemPage> fetchPage(int startingIndex) async {
|
||||
// If the [startingIndex] is beyond the bounds of the catalog, an
|
||||
// empty page will be returned.
|
||||
if (startingIndex > catalogLength) {
|
||||
return ItemPage(
|
||||
items: [],
|
||||
startingIndex: startingIndex,
|
||||
hasNext: false,
|
||||
);
|
||||
return ItemPage(items: [], startingIndex: startingIndex, hasNext: false);
|
||||
}
|
||||
|
||||
// The page of items is generated here.
|
||||
return ItemPage(
|
||||
items: List.generate(
|
||||
min(itemsPerPage, catalogLength - startingIndex),
|
||||
(index) => Item(
|
||||
color: Colors.primaries[index % Colors.primaries.length],
|
||||
name: 'Color #${startingIndex + index}',
|
||||
price: 50 + (index * 42) % 200,
|
||||
)),
|
||||
min(itemsPerPage, catalogLength - startingIndex),
|
||||
(index) => Item(
|
||||
color: Colors.primaries[index % Colors.primaries.length],
|
||||
name: 'Color #${startingIndex + index}',
|
||||
price: 50 + (index * 42) % 200,
|
||||
),
|
||||
),
|
||||
startingIndex: startingIndex,
|
||||
// Returns `false` if we've reached the [catalogLength].
|
||||
hasNext: startingIndex + itemsPerPage < catalogLength,
|
||||
|
||||
@@ -11,11 +11,7 @@ class Item {
|
||||
|
||||
final String name;
|
||||
|
||||
Item({
|
||||
required this.color,
|
||||
required this.name,
|
||||
required this.price,
|
||||
});
|
||||
Item({required this.color, required this.name, required this.price});
|
||||
|
||||
Item.loading() : this(color: Colors.grey, name: '...', price: 0);
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ class ItemTile extends StatelessWidget {
|
||||
child: ListTile(
|
||||
leading: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: Container(
|
||||
color: item.color,
|
||||
),
|
||||
child: Container(color: item.color),
|
||||
),
|
||||
title: Text(item.name, style: Theme.of(context).textTheme.titleLarge),
|
||||
trailing: Text('\$ ${(item.price / 100).toStringAsFixed(2)}'),
|
||||
@@ -41,10 +39,7 @@ class LoadingItemTile extends StatelessWidget {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListTile(
|
||||
leading: const AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: Placeholder(),
|
||||
),
|
||||
leading: const AspectRatio(aspectRatio: 1, child: Placeholder()),
|
||||
title: Text('...', style: Theme.of(context).textTheme.titleLarge),
|
||||
trailing: const Text('\$ ...'),
|
||||
),
|
||||
|
||||
@@ -5,7 +5,7 @@ publish_to: none
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: ^3.5.0
|
||||
sdk: ^3.7.0-0
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
|
||||
Reference in New Issue
Block a user