Unverified Commit 7982a3a2 authored by xster's avatar xster Committed by GitHub

New gallery performance improvements (#17167)

parent e77cfcf2
...@@ -52,37 +52,41 @@ class _CategoryItem extends StatelessWidget { ...@@ -52,37 +52,41 @@ class _CategoryItem extends StatelessWidget {
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
final bool isDark = theme.brightness == Brightness.dark; final bool isDark = theme.brightness == Brightness.dark;
return new RawMaterialButton( // This repaint boundary prevents the entire _CategoriesPage from being
padding: EdgeInsets.zero, // repainted when the button's ink splash animates.
splashColor: theme.primaryColor.withOpacity(0.12), return new RepaintBoundary(
highlightColor: Colors.transparent, child: new RawMaterialButton(
onPressed: onTap, padding: EdgeInsets.zero,
child: new Column( splashColor: theme.primaryColor.withOpacity(0.12),
mainAxisAlignment: MainAxisAlignment.end, highlightColor: Colors.transparent,
crossAxisAlignment: CrossAxisAlignment.center, onPressed: onTap,
children: <Widget>[ child: new Column(
new Padding( mainAxisAlignment: MainAxisAlignment.end,
padding: const EdgeInsets.all(6.0), crossAxisAlignment: CrossAxisAlignment.center,
child: new Icon( children: <Widget>[
category.icon, new Padding(
size: 60.0, padding: const EdgeInsets.all(6.0),
color: isDark ? Colors.white : _kFlutterBlue, child: new Icon(
), category.icon,
), size: 60.0,
const SizedBox(height: 10.0),
new Container(
height: 48.0,
alignment: Alignment.center,
child: new Text(
category.name,
textAlign: TextAlign.center,
style: theme.textTheme.subhead.copyWith(
fontFamily: 'GoogleSans',
color: isDark ? Colors.white : _kFlutterBlue, color: isDark ? Colors.white : _kFlutterBlue,
), ),
), ),
), const SizedBox(height: 10.0),
], new Container(
height: 48.0,
alignment: Alignment.center,
child: new Text(
category.name,
textAlign: TextAlign.center,
style: theme.textTheme.subhead.copyWith(
fontFamily: 'GoogleSans',
color: isDark ? Colors.white : _kFlutterBlue,
),
),
),
],
),
), ),
); );
} }
...@@ -112,33 +116,38 @@ class _CategoriesPage extends StatelessWidget { ...@@ -112,33 +116,38 @@ class _CategoriesPage extends StatelessWidget {
final double rowHeight = columnWidth * aspectRatio; final double rowHeight = columnWidth * aspectRatio;
final int rowCount = (categories.length + columnCount - 1) ~/ columnCount; final int rowCount = (categories.length + columnCount - 1) ~/ columnCount;
return new Column( // This repaint boundary prevents the inner contents of the front layer
mainAxisAlignment: MainAxisAlignment.center, // from repainting when the backdrop toggle triggers a repaint on the
mainAxisSize: MainAxisSize.min, // LayoutBuilder.
crossAxisAlignment: CrossAxisAlignment.stretch, return new RepaintBoundary(
children: new List<Widget>.generate(rowCount, (int rowIndex) { child: new Column(
final int columnCountForRow = rowIndex == rowCount - 1 mainAxisAlignment: MainAxisAlignment.center,
? categories.length - columnCount * math.max(0, rowCount - 1) mainAxisSize: MainAxisSize.min,
: columnCount; crossAxisAlignment: CrossAxisAlignment.stretch,
children: new List<Widget>.generate(rowCount, (int rowIndex) {
return new Row( final int columnCountForRow = rowIndex == rowCount - 1
children: new List<Widget>.generate(columnCountForRow, (int columnIndex) { ? categories.length - columnCount * math.max(0, rowCount - 1)
final int index = rowIndex * columnCount + columnIndex; : columnCount;
final GalleryDemoCategory category = categoriesList[index];
return new Row(
return new SizedBox( children: new List<Widget>.generate(columnCountForRow, (int columnIndex) {
width: columnWidth, final int index = rowIndex * columnCount + columnIndex;
height: rowHeight, final GalleryDemoCategory category = categoriesList[index];
child: new _CategoryItem(
category: category, return new SizedBox(
onTap: () { width: columnWidth,
onCategoryTap(category); height: rowHeight,
}, child: new _CategoryItem(
), category: category,
); onTap: () {
}), onCategoryTap(category);
); },
}), ),
);
}),
);
}),
),
); );
}, },
), ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment