From 4cf29ee958fbe2a9973ca1697089eb832d645456 Mon Sep 17 00:00:00 2001 From: toly <1981462002@qq.com> Date: Thu, 31 Dec 2020 12:19:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- android/key.properties | 4 - lib/views/pages/gallery/gallery_unit.dart | 95 +++++++++++++---------- 3 files changed, 53 insertions(+), 48 deletions(-) delete mode 100644 android/key.properties diff --git a/.gitignore b/.gitignore index 75f4982..21a18e2 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,7 @@ #.vscode/ - +/android/key.properties # Flutter/Dart/Pub related **/doc/api/ .dart_tool/ diff --git a/android/key.properties b/android/key.properties deleted file mode 100644 index 4a650df..0000000 --- a/android/key.properties +++ /dev/null @@ -1,4 +0,0 @@ -storePassword=toly1994 -keyPassword=toly1994 -keyAlias=key -storeFile=/Volumes/coder/file/key/toly.jks \ No newline at end of file diff --git a/lib/views/pages/gallery/gallery_unit.dart b/lib/views/pages/gallery/gallery_unit.dart index cce7887..a82c390 100644 --- a/lib/views/pages/gallery/gallery_unit.dart +++ b/lib/views/pages/gallery/gallery_unit.dart @@ -38,47 +38,51 @@ class _GalleryUnitState extends State { viewportFraction: 0.9, initialPage: _position, )..addListener(() { - double value2 = (_ctrl.page - _firstOffset + 1) % 5 / 5; - factor.value = value2 == 0 ? 1 : value2; + double value = (_ctrl.page - _firstOffset + 1) % 5 / 5; + factor.value = value == 0 ? 1 : value; }); } @override void dispose() { - super.dispose(); _ctrl.dispose(); + factor.dispose(); + super.dispose(); } Color get color => BlocProvider.of(context).state.color; Color get nextColor => BlocProvider.of(context).state.nextColor; + BoxDecoration get boxDecoration => BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.only( + topLeft: Radius.circular(40), topRight: Radius.circular(40))); + @override Widget build(BuildContext context) { return Scaffold( body: ValueListenableBuilder( + child: Column( + //使用 child 属性优化 + children: [ + _buildTitle(context), + Expanded( + child: Container( + margin: const EdgeInsets.only(left: 8, right: 8), + child: _buildContent(), + decoration: boxDecoration, + )) + ], + ), valueListenable: factor, - builder: (_, value, __) => Container( + builder: (_, value, child) => Container( color: Color.lerp( color, nextColor, value, ), - child: Column( - children: [ - _buildTitle(context), - Expanded( - child: Container( - child: _buildContent(), - margin: EdgeInsets.only(left: 8, right: 8), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.only( - topLeft: Radius.circular(40), - topRight: Radius.circular(40))), - )) - ], - ), + child: child, ), ), ); @@ -129,7 +133,7 @@ class _GalleryUnitState extends State { }).toList(); return Container( - padding: EdgeInsets.only(bottom: 80, top: 40), + padding: const EdgeInsets.only(bottom: 80, top: 40), child: Column( children: [ Expanded( @@ -137,33 +141,18 @@ class _GalleryUnitState extends State { controller: _ctrl, itemBuilder: (_, index) { return AnimatedBuilder( + child: Padding( + padding: const EdgeInsets.all(6.0), + child: widgets[ + _fixPosition(index, _firstOffset, widgets.length)], + ), animation: _ctrl, - builder: (context, child) { - double value; - if (_ctrl.position.haveDimensions) { - value = _ctrl.page - index; - } else { - value = (_position - index).toDouble(); - } - value = (1 - ((value.abs()) * .5)).clamp(0, 1).toDouble(); - value = Curves.easeOut.transform(value); - - return Center( - child: Transform( - transform: Matrix4.diagonal3Values(1.0, value, 1.0), - alignment: Alignment.center, - child: Padding( - padding: const EdgeInsets.all(6.0), - child: widgets[_fixPosition( - index, _firstOffset, widgets.length)], - ), - ), - ); - }, + builder: (context, child) => + _buildAnimItemByIndex(context, child, index), ); }, onPageChanged: (index) { - setState(() => _position = index); + _position = index; }, ), ), @@ -172,6 +161,26 @@ class _GalleryUnitState extends State { )); } + Widget _buildAnimItemByIndex(BuildContext context, Widget child, int index) { + double value; + if (_ctrl.position.haveDimensions) { + value = _ctrl.page - index; + } else { + value = (_position - index).toDouble(); + } + value = (1 - ((value.abs()) * .5)).clamp(0, 1).toDouble(); + value = Curves.easeOut.transform(value); + + return Transform( + transform: Matrix4.diagonal3Values(1.0, value, 1.0), + alignment: Alignment.center, + child: Padding( + padding: const EdgeInsets.all(6.0), + child: child, + ), + ); + } + Widget _buildDiver() => Container( margin: EdgeInsets.only(bottom: 12, left: 48, right: 48, top: 10), height: 2,