-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add scrollable_positioned_list dependency by source code
- Loading branch information
Showing
16 changed files
with
2,785 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/src/editor/editor_component/entry/page_block_component.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
lib/src/flutter/scrollable_positioned_list/scrollable_positioned_list.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Copyright 2019 The Fuchsia Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
export 'src/item_positions_listener.dart'; | ||
export 'src/scrollable_positioned_list.dart'; | ||
export 'src/scroll_offset_listener.dart'; |
98 changes: 98 additions & 0 deletions
98
lib/src/flutter/scrollable_positioned_list/src/element_registry.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2019 The Fuchsia 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/widgets.dart'; | ||
|
||
/// A registry to track some [Element]s in the tree. | ||
class RegistryWidget extends StatefulWidget { | ||
/// Creates a [RegistryWidget]. | ||
const RegistryWidget({Key? key, this.elementNotifier, required this.child}) | ||
: super(key: key); | ||
|
||
/// The widget below this widget in the tree. | ||
final Widget child; | ||
|
||
/// Contains the current set of all [Element]s created by | ||
/// [RegisteredElementWidget]s in the tree below this widget. | ||
/// | ||
/// Note that if there is another [RegistryWidget] in this widget's subtree | ||
/// that registry, and not this one, will collect elements in its subtree. | ||
final ValueNotifier<Set<Element>?>? elementNotifier; | ||
|
||
@override | ||
State<StatefulWidget> createState() => _RegistryWidgetState(); | ||
} | ||
|
||
/// A widget whose [Element] will be added its nearest ancestor | ||
/// [RegistryWidget]. | ||
class RegisteredElementWidget extends ProxyWidget { | ||
/// Creates a [RegisteredElementWidget]. | ||
const RegisteredElementWidget({Key? key, required Widget child}) | ||
: super(key: key, child: child); | ||
|
||
@override | ||
Element createElement() => _RegisteredElement(this); | ||
} | ||
|
||
class _RegistryWidgetState extends State<RegistryWidget> { | ||
final Set<Element> registeredElements = {}; | ||
|
||
@override | ||
Widget build(BuildContext context) => _InheritedRegistryWidget( | ||
state: this, | ||
child: widget.child, | ||
); | ||
} | ||
|
||
class _InheritedRegistryWidget extends InheritedWidget { | ||
final _RegistryWidgetState state; | ||
|
||
const _InheritedRegistryWidget({ | ||
Key? key, | ||
required this.state, | ||
required Widget child, | ||
}) : super(key: key, child: child); | ||
|
||
@override | ||
bool updateShouldNotify(InheritedWidget oldWidget) => true; | ||
} | ||
|
||
class _RegisteredElement extends ProxyElement { | ||
_RegisteredElement(ProxyWidget widget) : super(widget); | ||
|
||
@override | ||
void notifyClients(ProxyWidget oldWidget) {} | ||
|
||
late _RegistryWidgetState _registryWidgetState; | ||
|
||
@override | ||
void mount(Element? parent, dynamic newSlot) { | ||
super.mount(parent, newSlot); | ||
final inheritedRegistryWidget = | ||
dependOnInheritedWidgetOfExactType<_InheritedRegistryWidget>()!; | ||
_registryWidgetState = inheritedRegistryWidget.state; | ||
_registryWidgetState.registeredElements.add(this); | ||
_registryWidgetState.widget.elementNotifier?.value = | ||
_registryWidgetState.registeredElements; | ||
} | ||
|
||
@override | ||
void didChangeDependencies() { | ||
super.didChangeDependencies(); | ||
final inheritedRegistryWidget = | ||
dependOnInheritedWidgetOfExactType<_InheritedRegistryWidget>()!; | ||
_registryWidgetState = inheritedRegistryWidget.state; | ||
_registryWidgetState.registeredElements.add(this); | ||
_registryWidgetState.widget.elementNotifier?.value = | ||
_registryWidgetState.registeredElements; | ||
} | ||
|
||
@override | ||
void unmount() { | ||
_registryWidgetState.registeredElements.remove(this); | ||
_registryWidgetState.widget.elementNotifier?.value = | ||
_registryWidgetState.registeredElements; | ||
super.unmount(); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
lib/src/flutter/scrollable_positioned_list/src/item_positions_listener.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2019 The Fuchsia 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/foundation.dart'; | ||
|
||
import 'item_positions_notifier.dart'; | ||
import 'scrollable_positioned_list.dart'; | ||
|
||
/// Provides a listenable iterable of [itemPositions] of items that are on | ||
/// screen and their locations. | ||
abstract class ItemPositionsListener { | ||
/// Creates an [ItemPositionsListener] that can be used by a | ||
/// [ScrollablePositionedList] to return the current position of items. | ||
factory ItemPositionsListener.create() => ItemPositionsNotifier(); | ||
|
||
/// The position of items that are at least partially visible in the viewport. | ||
ValueListenable<Iterable<ItemPosition>> get itemPositions; | ||
} | ||
|
||
/// Position information for an item in the list. | ||
class ItemPosition { | ||
/// Create an [ItemPosition]. | ||
const ItemPosition({ | ||
required this.index, | ||
required this.itemLeadingEdge, | ||
required this.itemTrailingEdge, | ||
}); | ||
|
||
/// Index of the item. | ||
final int index; | ||
|
||
/// Distance in proportion of the viewport's main axis length from the leading | ||
/// edge of the viewport to the leading edge of the item. | ||
/// | ||
/// May be negative if the item is partially visible. | ||
final double itemLeadingEdge; | ||
|
||
/// Distance in proportion of the viewport's main axis length from the leading | ||
/// edge of the viewport to the trailing edge of the item. | ||
/// | ||
/// May be greater than one if the item is partially visible. | ||
final double itemTrailingEdge; | ||
|
||
@override | ||
bool operator ==(dynamic other) { | ||
if (other.runtimeType != runtimeType) return false; | ||
final ItemPosition otherPosition = other; | ||
return otherPosition.index == index && | ||
otherPosition.itemLeadingEdge == itemLeadingEdge && | ||
otherPosition.itemTrailingEdge == itemTrailingEdge; | ||
} | ||
|
||
@override | ||
int get hashCode => | ||
31 * (31 * (7 + index.hashCode) + itemLeadingEdge.hashCode) + | ||
itemTrailingEdge.hashCode; | ||
|
||
@override | ||
String toString() => | ||
'ItemPosition(index: $index, itemLeadingEdge: $itemLeadingEdge, itemTrailingEdge: $itemTrailingEdge)'; | ||
} |
13 changes: 13 additions & 0 deletions
13
lib/src/flutter/scrollable_positioned_list/src/item_positions_notifier.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2019 The Fuchsia 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/foundation.dart'; | ||
|
||
import 'item_positions_listener.dart'; | ||
|
||
/// Internal implementation of [ItemPositionsListener]. | ||
class ItemPositionsNotifier implements ItemPositionsListener { | ||
@override | ||
final ValueNotifier<Iterable<ItemPosition>> itemPositions = ValueNotifier([]); | ||
} |
Oops, something went wrong.