From 3b915be9d361254f64da6ef691b00464316a121c Mon Sep 17 00:00:00 2001 From: poka Date: Mon, 22 Feb 2021 19:44:58 +0100 Subject: [PATCH] Fix Snack display --- lib/screens/history.dart | 249 +++++++++++++++-------------- lib/screens/home.dart | 399 +++++++++++++++++++++++++---------------------- 2 files changed, 343 insertions(+), 305 deletions(-) diff --git a/lib/screens/history.dart b/lib/screens/history.dart index f1f40f7..e9ec8cb 100644 --- a/lib/screens/history.dart +++ b/lib/screens/history.dart @@ -162,128 +162,139 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { // Build history list return NotificationListener( - child: Expanded( - child: ListView( - controller: scrollController, - children: [ - SizedBox(height: 20), - if (_historyProvider.pubkey != '') - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ + child: Builder( + builder: (context) => Expanded( + child: ListView( + controller: scrollController, + children: [ + SizedBox(height: 20), + if (_historyProvider.pubkey != '') + Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + if (_isFirstExec) + Container( + padding: const EdgeInsets.fromLTRB( + 12, 0, 5, 0), + child: FutureBuilder( + future: + _cesiumPlusProvider.getAvatar( + _historyProvider.pubkey), + initialData: [ + File(appPath.path + + '/default_avatar.png') + ], + builder: (BuildContext context, + AsyncSnapshot _avatar) { + cesiumData = _avatar.data; + // _cesiumPlusProvider.isComplete = true; + if (_avatar.connectionState != + ConnectionState.done) { + return Image.file( + File(appPath.path + + '/default_avatar.png'), + height: avatarsSize); + } + if (_avatar.hasError) { + return Image.file( + File(appPath.path + + '/default_avatar.png'), + height: avatarsSize); + } + if (_avatar.hasData) { + return SingleChildScrollView( + padding: + EdgeInsets.all(0.0), + child: Image.file( + _avatar.data[0], + height: avatarsSize)); + } + return Image.file( + File(appPath.path + + '/default_avatar.png'), + height: avatarsSize); + })), + GestureDetector( + onTap: () { + Clipboard.setData(ClipboardData( + text: _historyProvider.pubkey)); + _historyProvider.snackCopyKey(context); + }, + child: Text( + _historyProvider.getShortPubkey( + _historyProvider.pubkey), + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.w800, + fontFamily: 'Monospace')), + ), + Container( + padding: const EdgeInsets.fromLTRB( + 30, 0, 5, 0), // .only(right: 15), + child: Text('TODO')), + SizedBox(width: 0) + ]), + if (_isFirstExec) + Row( + mainAxisAlignment: + MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + padding: const EdgeInsets.fromLTRB( + 0, 0, 0, 0), + // padding: const EdgeInsets., + child: FutureBuilder( + future: _cesiumPlusProvider.getName( + _historyProvider.pubkey), + initialData: '...', + builder: (context, snapshot) { + return Text( + snapshot.data != '' + ? snapshot.data + : '-', + style: + TextStyle(fontSize: 20)); + })) + ]), + SizedBox(height: 18), if (_isFirstExec) Container( padding: - const EdgeInsets.fromLTRB(12, 0, 5, 0), - child: FutureBuilder( - future: _cesiumPlusProvider - .getAvatar(_historyProvider.pubkey), - initialData: [ - File(appPath.path + - '/default_avatar.png') - ], - builder: (BuildContext context, - AsyncSnapshot _avatar) { - cesiumData = _avatar.data; - // _cesiumPlusProvider.isComplete = true; - if (_avatar.connectionState != - ConnectionState.done) { - return Image.file( - File(appPath.path + - '/default_avatar.png'), - height: avatarsSize); - } - if (_avatar.hasError) { - return Image.file( - File(appPath.path + - '/default_avatar.png'), - height: avatarsSize); - } - if (_avatar.hasData) { - return SingleChildScrollView( - padding: EdgeInsets.all(0.0), - child: Image.file(_avatar.data[0], - height: avatarsSize)); - } - return Image.file( - File(appPath.path + - '/default_avatar.png'), - height: avatarsSize); - })), - GestureDetector( - onTap: () { - Clipboard.setData(ClipboardData( - text: _historyProvider.pubkey)); - _historyProvider.snackCopyKey(context); - }, - child: Text( - _historyProvider - .getShortPubkey(_historyProvider.pubkey), - style: TextStyle( - fontSize: 22, - fontWeight: FontWeight.w800, - fontFamily: 'Monospace')), - ), - Container( - padding: const EdgeInsets.fromLTRB( - 30, 0, 5, 0), // .only(right: 15), - child: Text('TODO')), - SizedBox(width: 0) - ]), - if (_isFirstExec) - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Container( - padding: const EdgeInsets.fromLTRB(0, 0, 0, 0), - // padding: const EdgeInsets., - child: FutureBuilder( - future: _cesiumPlusProvider - .getName(_historyProvider.pubkey), - initialData: '...', - builder: (context, snapshot) { - return Text( - snapshot.data != '' - ? snapshot.data - : '-', - style: TextStyle(fontSize: 20)); - })) - ]), - SizedBox(height: 18), - if (_isFirstExec) - Container( - padding: const EdgeInsets.fromLTRB(0, 0, 0, 0), - child: Text(balance.toString() + ' Ğ1', - textAlign: TextAlign.center, - style: TextStyle(fontSize: 18.0))), - SizedBox(height: 20), - ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 1, - primary: Colors.grey[50], // background - onPrimary: Colors.black, // foreground - ), - onPressed: () { - _historyProvider.switchProfileView(); - }, - child: Text(_historyProvider.historySwitchButtun, - style: TextStyle( - fontSize: 15, color: Color(0xffD28928)))), - // const Divider( - // color: Colors.grey, - // height: 5, - // thickness: 0.5, - // indent: 0, - // endIndent: 0, - // ), - _historyProvider.isHistoryScreen - ? historyView(context, result) - : payView(context), - ], - )), + const EdgeInsets.fromLTRB(0, 0, 0, 0), + child: Text(balance.toString() + ' Ğ1', + textAlign: TextAlign.center, + style: TextStyle(fontSize: 18.0))), + SizedBox(height: 20), + ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 1, + primary: Colors.grey[50], // background + onPrimary: Colors.black, // foreground + ), + onPressed: () { + _historyProvider.switchProfileView(); + }, + child: Text( + _historyProvider.historySwitchButtun, + style: TextStyle( + fontSize: 15, + color: Color(0xffD28928)))), + // const Divider( + // color: Colors.grey, + // height: 5, + // thickness: 0.5, + // indent: 0, + // endIndent: 0, + // ), + _historyProvider.isHistoryScreen + ? historyView(context, result) + : payView(context), + ], + ))), onNotification: (t) { if (t is ScrollEndNotification && scrollController.position.pixels >= diff --git a/lib/screens/home.dart b/lib/screens/home.dart index ee1a738..e0c7f14 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -12,8 +12,7 @@ class HomeScreen extends StatelessWidget { Widget build(BuildContext context) { HomeProvider _homeProvider = Provider.of(context); HistoryProvider _historyProvider = Provider.of(context); - // _historyProvider.snackNode(context); - + HistoryProvider _historyStatic = HistoryProvider(''); return Scaffold( resizeToAvoidBottomInset: false, drawer: Drawer( @@ -74,13 +73,6 @@ class HomeScreen extends StatelessWidget { icon: _homeProvider.searchIcon, color: Colors.grey[850], onPressed: () { - // Navigator.push( - // context, - // MaterialPageRoute(builder: (context) { - // return SearchList(); - // }), - // ); - if (_homeProvider.searchIcon.icon == Icons.search) { _homeProvider.searchIcon = Icon( Icons.close, @@ -115,183 +107,218 @@ class HomeScreen extends StatelessWidget { backgroundColor: Color(0xffFFD58D), ), backgroundColor: Color(0xffF9F9F1), - body: // _homeProvider.currentTab[_homeProvider.currentIndex], - Builder( - builder: (context) => Column(children: [ - // _historyProvider.snackNode(context), - // SnackBar(content: Text('tataaa')), - - Padding( - padding: EdgeInsets.only(top: 22), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox(width: 7), - Image( - image: AssetImage('assets/icon/gecko_final.png'), - height: 180), - ])), - Padding( - padding: EdgeInsets.only(top: 15), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "L’application de paiement Ğ1\nplus mobile qu’un lésard du Vietnam", - textAlign: TextAlign.center, - style: TextStyle(color: Colors.black, fontSize: 15), - ) - ])), - Padding( - padding: EdgeInsets.only(top: 60), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Column(children: [ - Container( - child: ClipOval( - child: Material( - color: Color(0xffFFD58D), // button color - child: InkWell( - splashColor: - Color(0xffD28928), // inkwell color - child: Padding( - padding: EdgeInsets.all(17), - child: Image( - image: AssetImage( - 'assets/qrcode-scan.png'), - height: 58)), - onTap: () async { - await _historyProvider.scan(context); - }), - ), - ), - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Colors.grey, - blurRadius: 4.0, - offset: Offset(2.0, 2.5), - spreadRadius: 0.5) - ], - ), - ), - SizedBox(height: 10), - Text( - "Payer par QR-Code", - textAlign: TextAlign.center, - style: TextStyle(color: Colors.black, fontSize: 13), - ) - ]) - ])), - Padding( - padding: EdgeInsets.only(top: 60), - child: - Row(mainAxisAlignment: MainAxisAlignment.center, children: < - Widget>[ - Column(children: [ - Container( - child: ClipOval( - child: Material( - color: Color(0xffFFD58D), // button color - child: InkWell( - splashColor: Color(0xffD28928), // inkwell color - child: Padding( - padding: EdgeInsets.symmetric( - horizontal: 18, vertical: 14), - child: Image( - image: - AssetImage('assets/blockchain.png'), - height: 65)), - onTap: () {}), - ), - ), - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Colors.grey, - blurRadius: 4.0, - offset: Offset(2.0, 2.5), - spreadRadius: 0.5) - ], - ), - ), - SizedBox(height: 10), - Text( - "Explorer\n", - textAlign: TextAlign.center, - style: TextStyle(color: Colors.black, fontSize: 13), - ) + body: Builder( + builder: (ctx) => StatefulWrapper( + onInit: () { + WidgetsBinding.instance.addPostFrameCallback((_) { + _historyStatic.snackNode(ctx); + }); + }, + child: Column(children: [ + Padding( + padding: EdgeInsets.only(top: 22), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox(width: 7), + Image( + image: + AssetImage('assets/icon/gecko_final.png'), + height: 180), + ])), + Padding( + padding: EdgeInsets.only(top: 15), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "L’application de paiement Ğ1\nplus mobile qu’un lésard du Vietnam", + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.black, fontSize: 15), + ) + ])), + Padding( + padding: EdgeInsets.only(top: 60), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Column(children: [ + Container( + child: ClipOval( + child: Material( + color: Color(0xffFFD58D), // button color + child: InkWell( + splashColor: Color( + 0xffD28928), // inkwell color + child: Padding( + padding: EdgeInsets.all(17), + child: Image( + image: AssetImage( + 'assets/qrcode-scan.png'), + height: 58)), + onTap: () async { + await _historyProvider + .scan(context); + }), + ), + ), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.grey, + blurRadius: 4.0, + offset: Offset(2.0, 2.5), + spreadRadius: 0.5) + ], + ), + ), + SizedBox(height: 10), + Text( + "Payer par QR-Code", + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.black, fontSize: 13), + ) + ]) + ])), + Padding( + padding: EdgeInsets.only(top: 60), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Column(children: [ + Container( + child: ClipOval( + child: Material( + color: Color(0xffFFD58D), // button color + child: InkWell( + splashColor: Color( + 0xffD28928), // inkwell color + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: 18, vertical: 14), + child: Image( + image: AssetImage( + 'assets/blockchain.png'), + height: 65)), + onTap: () {}), + ), + ), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.grey, + blurRadius: 4.0, + offset: Offset(2.0, 2.5), + spreadRadius: 0.5) + ], + ), + ), + SizedBox(height: 10), + Text( + "Explorer\n", + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.black, fontSize: 13), + ) + ]), + SizedBox(width: 140), + Column(children: [ + Container( + child: ClipOval( + child: Material( + color: Color(0xffFFD58D), // button color + child: InkWell( + splashColor: Color( + 0xffD28928), // inkwell color + child: Padding( + padding: EdgeInsets.all(20), + child: Image( + image: AssetImage( + 'assets/lock.png'), + height: 50)), + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return WalletsHome(); + }), + ); + }), + ), + ), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.grey, + blurRadius: 4.0, + offset: Offset(2.0, 2.5), + spreadRadius: 0.5) + ], + ), + ), + SizedBox(height: 10), + Text( + "Gérer mes\nportefeuilles", + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.black, fontSize: 13), + ) + ]) + ])) ]), - SizedBox(width: 140), - Column(children: [ - Container( - child: ClipOval( - child: Material( - color: Color(0xffFFD58D), // button color - child: InkWell( - splashColor: Color(0xffD28928), // inkwell color - child: Padding( - padding: EdgeInsets.all(20), - child: Image( - image: AssetImage('assets/lock.png'), - height: 50)), - onTap: () { - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return WalletsHome(); - }), - ); - }), - ), - ), - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Colors.grey, - blurRadius: 4.0, - offset: Offset(2.0, 2.5), - spreadRadius: 0.5) - ], - ), - ), - SizedBox(height: 10), - Text( - "Gérer mes\nportefeuilles", - textAlign: TextAlign.center, - style: TextStyle(color: Colors.black, fontSize: 13), - ) - ]) - ])) - ]), - // bottomNavigationBar: BottomNavigationBar( - // backgroundColor: Color(0xffFFD58D), - // fixedColor: Colors.grey[850], - // unselectedItemColor: Color(0xffBD935C), - // type: BottomNavigationBarType.fixed, - // onTap: (index) { - // _homeProvider.currentIndex = index; - // }, - // currentIndex: _homeProvider.currentIndex, - // items: [ - // BottomNavigationBarItem( - // icon: Image.asset('assets/block-space-disabled.png', height: 26), - // activeIcon: Image.asset('assets/blockchain.png', height: 26), - // label: 'Explorateur', - // ), - // BottomNavigationBarItem( - // icon: Icon(Icons.lock), - // label: 'Mes portefeuilles', - // ), - // ], - // ), - )); + // bottomNavigationBar: BottomNavigationBar( + // backgroundColor: Color(0xffFFD58D), + // fixedColor: Colors.grey[850], + // unselectedItemColor: Color(0xffBD935C), + // type: BottomNavigationBarType.fixed, + // onTap: (index) { + // _homeProvider.currentIndex = index; + // }, + // currentIndex: _homeProvider.currentIndex, + // items: [ + // BottomNavigationBarItem( + // icon: Image.asset('assets/block-space-disabled.png', height: 26), + // activeIcon: Image.asset('assets/blockchain.png', height: 26), + // label: 'Explorateur', + // ), + // BottomNavigationBarItem( + // icon: Icon(Icons.lock), + // label: 'Mes portefeuilles', + // ), + // ], + // ), + ))); + } +} + +class StatefulWrapper extends StatefulWidget { + final Function onInit; + final Widget child; + const StatefulWrapper({@required this.onInit, @required this.child}); + @override + _StatefulWrapperState createState() => _StatefulWrapperState(); +} + +class _StatefulWrapperState extends State { + @override + void initState() { + if (widget.onInit != null) { + widget.onInit(); + } + super.initState(); + } + + @override + Widget build(BuildContext context) { + return widget.child; } }