From f28f35ffb13a948b64c5f0bc9239cb5f9f702b93 Mon Sep 17 00:00:00 2001 From: Codelessly Date: Thu, 5 Sep 2024 22:04:43 -0500 Subject: [PATCH] Optimize Main ListView --- lib/main.dart | 72 +++++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 62cce10..bbf225a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -22,42 +22,16 @@ class MyApp extends StatelessWidget { const Breakpoint(start: 1081, end: double.infinity, name: DESKTOP), ]), home: Scaffold( - body: SingleChildScrollView( - scrollDirection: Axis.vertical, - child: Listener( - onPointerDown: (event) { - // Clear Header search TextField focus. - FocusScope.of(context).requestFocus(FocusNode()); - }, - child: Column( - children: [ - const MenuHeader(), - const Header(), - const FlutterFavorites(), - // Background squares image container. - Container( - constraints: - const BoxConstraints(maxWidth: 1440, minWidth: 1440), - decoration: const BoxDecoration( - image: DecorationImage( - image: AssetImage('assets/images/bg_squares.png'), - fit: BoxFit.fitWidth, - alignment: Alignment.center)), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - const MostPopular(), - const TopFlutter(), - const TopDart(), - Container(height: 92), - ], - ), - ), - const Footer(), - ], - ), - ), + body: Listener( + onPointerDown: (event) { + // Clear Header search TextField focus. + FocusScope.of(context).requestFocus(FocusNode()); + }, + child: ListView.builder( + itemCount: blocks.length, + itemBuilder: (context, index) { + return blocks[index]; + }), ), backgroundColor: Colors.white, ), @@ -65,3 +39,29 @@ class MyApp extends StatelessWidget { ); } } + +List blocks = [ + const MenuHeader(), + const Header(), + const FlutterFavorites(), + // Background squares image container. + Container( + constraints: const BoxConstraints(maxWidth: 1440, minWidth: 1440), + decoration: const BoxDecoration( + image: DecorationImage( + image: AssetImage('assets/images/bg_squares.png'), + fit: BoxFit.fitWidth, + alignment: Alignment.center)), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const MostPopular(), + const TopFlutter(), + const TopDart(), + Container(height: 92), + ], + ), + ), + const Footer(), +];