Created
November 16, 2021 09:48
-
-
Save ambrizals/af38f9852ef0b085af9af630913c3747 to your computer and use it in GitHub Desktop.
Some experiment to explore NestedScrollView widget & Sliver widget
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
import 'package:bbd_client_manager/components/Global/Tab.dart'; | |
import 'package:bbd_client_manager/components/Transaksi/Detail/v2/header_component.dart'; | |
import 'package:bbd_client_manager/components/Transaksi/Detail/v2/info_pengiriman_component.dart'; | |
import 'package:bbd_client_manager/components/Transaksi/Detail/v2/info_pesanan_component.dart'; | |
import 'package:bbd_client_manager/pages/transaksi/v2/detail/daftar_item_part.dart'; | |
import 'package:bbd_client_manager/pages/transaksi/v2/detail/daftar_pembayaran_part.dart'; | |
import 'package:bbd_client_manager/pages/transaksi/v2/detail/daftar_pengeluaran_part.dart'; | |
import 'package:flutter/material.dart'; | |
import 'dart:math' as math; | |
class TransaksiDetailv2Page extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return CollapsingList(); | |
} | |
} | |
class _SliverHeaderDelegate extends SliverPersistentHeaderDelegate { | |
_SliverHeaderDelegate({ | |
required this.minHeight, | |
required this.maxHeight, | |
required this.child, | |
}); | |
final double minHeight; | |
final double maxHeight; | |
final Widget child; | |
@override | |
double get minExtent => minHeight; | |
@override | |
double get maxExtent => math.max(maxHeight, minHeight); | |
@override | |
Widget build( | |
BuildContext context, double shrinkOffset, bool overlapsContent) { | |
return new SizedBox.expand(child: child); | |
} | |
@override | |
bool shouldRebuild(_SliverHeaderDelegate oldDelegate) { | |
return maxHeight != oldDelegate.maxHeight || | |
minHeight != oldDelegate.minHeight || | |
child != oldDelegate.child; | |
} | |
} | |
class CollapsingList extends StatefulWidget { | |
@override | |
State<CollapsingList> createState() => _CollapsingListState(); | |
} | |
class _CollapsingListState extends State<CollapsingList> | |
with TickerProviderStateMixin { | |
late TabController _tabController; | |
@override | |
void initState() { | |
super.initState(); | |
_tabController = TabController(length: 3, vsync: this, initialIndex: 0); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.white, | |
body: NestedScrollView( | |
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) { | |
return [ | |
Theme( | |
data: ThemeData( | |
appBarTheme: AppBarTheme( | |
elevation: 0, | |
color: Colors.brown.shade700, | |
iconTheme: IconThemeData(color: Colors.white))), | |
child: SliverAppBar( | |
expandedHeight: 130.0, | |
pinned: true, | |
centerTitle: true, | |
flexibleSpace: FlexibleSpaceBar( | |
collapseMode: CollapseMode.pin, | |
centerTitle: true, | |
title: Text( | |
'Transaksi', | |
style: TextStyle(fontSize: 18), | |
), | |
), | |
), | |
), | |
SliverToBoxAdapter(child: TransaksiHeaderComponent()), | |
SliverToBoxAdapter( | |
child: TransaksiInfoPengirimanComponent(), | |
), | |
SliverToBoxAdapter(child: Divider()), | |
SliverToBoxAdapter( | |
child: TransaksiInfoPesananComponent(), | |
), | |
SliverToBoxAdapter( | |
child: Divider(), | |
), | |
SliverPersistentHeader( | |
pinned: true, | |
delegate: _SliverHeaderDelegate( | |
minHeight: 52, | |
maxHeight: 52, | |
child: Container( | |
padding: const EdgeInsets.symmetric(vertical: 12), | |
color: Colors.white, | |
child: TabComponent(controller: _tabController, item: [ | |
TabItemComponent( | |
label: 'Daftar Item', | |
), | |
TabItemComponent( | |
label: 'Pembayaran', | |
), | |
TabItemComponent( | |
label: 'Pengeluaran', | |
), | |
]), | |
)), | |
), | |
]; | |
}, | |
body: TabBarView(controller: _tabController, children: [ | |
TransaksiDetailDaftaritemPart(), | |
TransaksiDetailDaftarPembayaranPart(), | |
TransaksiDetailDaftarPengeluaranPart() | |
]), | |
), | |
bottomNavigationBar: SingleChildScrollView( | |
scrollDirection: Axis.horizontal, | |
child: Padding( | |
padding: const EdgeInsets.symmetric(vertical: 6), | |
child: Wrap( | |
spacing: 12, | |
children: [ | |
Padding(padding: EdgeInsets.only(left: 2)), | |
OutlinedButton.icon( | |
onPressed: null, | |
icon: Icon(Icons.check), | |
label: Text('Selesaikan Transaksi')), | |
OutlinedButton.icon( | |
onPressed: null, | |
label: Text('Proses Transaksi'), | |
icon: Icon(Icons.play_circle), | |
), | |
OutlinedButton.icon( | |
onPressed: null, | |
label: Text('Batalkan Transaksi'), | |
icon: Icon(Icons.highlight_off), | |
), | |
Padding(padding: EdgeInsets.only(right: 2)) | |
], | |
), | |
)), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment