Skip to content

Commit

Permalink
Use PageView builder to address performance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
erdemyerebasmaz committed Sep 9, 2024
1 parent abc9a17 commit 6a9135b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/routes/receive_payment/receive_payment_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ class _ReceivePaymentPageState extends State<ReceivePaymentPage> {
ReceiveBitcoinAddressPaymentPage(),
];

final List<Widget> _memoizedPages = [];

Widget _getPage(int index) {
if (_memoizedPages.length <= index) {
_memoizedPages.add(pages[index]);
}
return _memoizedPages[index];
}

@override
void dispose() {
pageController.dispose();
Expand Down Expand Up @@ -88,11 +97,12 @@ class _ReceivePaymentPageState extends State<ReceivePaymentPage> {
),
),
Expanded(
child: PageView(
child: PageView.builder(
physics: const NeverScrollableScrollPhysics(),
controller: pageController,
onPageChanged: _onPageChanged,
children: pages,
itemCount: pages.length,
itemBuilder: (context, index) => _getPage(index),
),
),
],
Expand Down

0 comments on commit 6a9135b

Please sign in to comment.