Last active
October 23, 2021 08:35
-
-
Save jeckymodi/f65b504b54be5788501209e510f742e0 to your computer and use it in GitHub Desktop.
Account
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:demo_provider/Account/AccountLink.dart'; | |
import 'package:demo_provider/Account/DelinkAccount.dart'; | |
import 'package:demo_provider/LocaleProvider/LocaleProvider.dart'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/painting.dart'; | |
import 'package:flutter/widgets.dart'; | |
import 'package:provider/provider.dart'; | |
class AccountScreen extends StatefulWidget { | |
AccountScreen({Key? key}) : super(key: key); | |
@override | |
_AccountScreenState createState() => _AccountScreenState(); | |
} | |
class _AccountScreenState extends State<AccountScreen> { | |
double currentPageValue = 0; | |
PageController controller = PageController(); | |
@override | |
void initState() { | |
super.initState(); | |
controller.addListener(() { | |
setState(() { | |
currentPageValue = controller.page!; | |
print(currentPageValue); | |
}); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Consumer<PageNotifier>( | |
builder: (context, provider, snapshot) { | |
return Scaffold( | |
appBar: AppBar( | |
backgroundColor: Colors.white, | |
title: Text( | |
"Demo App", | |
style: TextStyle(color: Colors.black), | |
), | |
), | |
backgroundColor: Colors.white, | |
body: Column( | |
children: [ | |
getSegmentButtons(), | |
SizedBox(height: 20), | |
getPageView(), | |
], | |
), | |
); | |
}, | |
); | |
} | |
getSegmentButtons() { | |
return Padding( | |
padding: EdgeInsets.only(left: 20, right: 20, top: 10), | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
children: [ | |
getButtonItem("Linked Accounts", currentPageValue == 0, onTap: () { | |
setState(() { | |
currentPageValue = 0; | |
controller.animateToPage(currentPageValue.toInt(), | |
duration: Duration(milliseconds: 500), curve: Curves.easeIn); | |
print(currentPageValue); | |
}); | |
}), | |
getButtonItem("Delinked Accounts", currentPageValue == 1, onTap: () { | |
setState(() { | |
currentPageValue = 1; | |
controller.animateToPage(currentPageValue.toInt(), | |
duration: Duration(milliseconds: 500), curve: Curves.easeIn); | |
print(currentPageValue); | |
}); | |
}), | |
], | |
), | |
); | |
} | |
getButtonItem(String title, bool isSelected, {VoidCallback? onTap}) { | |
return Expanded( | |
child: GestureDetector( | |
onTap: onTap, | |
child: Container( | |
height: 45, | |
decoration: BoxDecoration( | |
color: isSelected ? Colors.blue : Colors.white, | |
borderRadius: BorderRadius.circular(22.4), | |
), | |
child: Center( | |
child: Text( | |
title, | |
style: TextStyle( | |
fontSize: 14, | |
color: isSelected ? Colors.white : Colors.grey.withOpacity(0.5), | |
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500, | |
), | |
), | |
), | |
), | |
), | |
); | |
} | |
getPageView() { | |
return Expanded( | |
child: PageView.builder( | |
controller: controller, | |
itemCount: 2, | |
physics: NeverScrollableScrollPhysics(), | |
itemBuilder: (context, position) { | |
if (position == 0) { | |
return AccountLinkedScreen(); | |
} | |
return DeAccountLinkedScreen(); | |
}, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment