You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

185 lines
5.9 KiB

3 years ago
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:teso/Classes/TesoUser.dart';
import 'package:teso/util/SizeConfig.dart';
import 'package:teso/util/consts.dart';
import 'package:flutter/material.dart';
import 'package:teso/Pages/PageWidgets/Personal/header.dart';
import 'package:teso/Pages/Sub_Pages/PersonalSub/Friends.dart';
import 'package:teso/Pages/Sub_Pages/PersonalSub/Posts.dart';
import 'package:teso/Pages/Sub_Pages/PersonalSub/Recently.dart';
import 'package:teso/providers/user_provider.dart';
import 'package:provider/provider.dart';
class Personnal extends StatefulWidget {
final Function showSettings;
const Personnal({Key key, this.showSettings}) : super(key: key);
@override
_PersonnalState createState() =>
_PersonnalState(showSettings: this.showSettings);
}
enum AppBarBehavior { normal, pinned, floating, snapping }
class _PersonnalState extends State<Personnal> with TickerProviderStateMixin {
TesoUser currentUser;
Function showSettings;
double scale;
_PersonnalState({this.showSettings});
double _appBarHeightSpecial = 275.0;
RefreshController _refreshController =
RefreshController(initialRefresh: false);
TabController tabsController;
Widget _randomHeightWidgets(BuildContext context) {
return Consumer<UserProvider>(
builder: (BuildContext context, UserProvider user, Widget child) {
user.getCurrentUser();
currentUser = user.currentUser;
if (user.currentUser == null || currentUser == null) {
return Container();
} else {
String dp = userdpURL + currentUser.thumbnail_dp;
return buildProfileHeader(
context,
currentUser.gold,
currentUser.silver,
currentUser.username,
dp,
user.friends != null
? user.friends.length.toString()
: currentUser.friends,
currentUser.firstname + " " + currentUser.lastname,
_appBarHeightSpecial);
}
});
}
void _onRefresh() async {
Provider.of<UserProvider>(context, listen: false).getUserInformation();
switch (tabsController.index) {
case 0:
await Provider.of<UserProvider>(context, listen: false).pullAds();
Provider.of<UserProvider>(context, listen: false).loadFriends();
Provider.of<UserProvider>(context, listen: false).getCoupons();
break;
case 1:
await Provider.of<UserProvider>(context, listen: false).loadFriends();
Provider.of<UserProvider>(context, listen: false).getCoupons();
Provider.of<UserProvider>(context, listen: false).pullAds();
break;
default:
break;
}
_refreshController.refreshCompleted();
}
@override
void initState() {
super.initState();
tabsController = new TabController(length: 3, initialIndex: 0, vsync: this);
}
@override
void dispose() {
tabsController.dispose();
_refreshController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
SizeConfig().init(context);
return Scaffold(
extendBody: true,
appBar: PreferredSize(
preferredSize: Size.fromHeight(SizeConfig.blockSizeHorizontal * 73.1),
child: Column(
children: [
AppBar(
backgroundColor: Colors.transparent,
toolbarHeight: 50,
automaticallyImplyLeading: false,
title: Consumer<UserProvider>(
builder:
(BuildContext context, UserProvider user, Widget child) {
currentUser = user.currentUser;
if (user.currentUser == null || currentUser == null) {
return Container();
} else {
return Text(user.currentUser.username,
style: TextStyle(
color: Theme.of(context).primaryColorLight,
));
}
},
),
actions: [
Container(
width: 50,
child: Align(
alignment: Alignment.topRight,
child: Container(
margin: EdgeInsets.only(top: 10),
height: 30.0,
width: 45.0,
//color: Color.fromRGBO(0, 0, 0, 0.4),
decoration: new BoxDecoration(
shape: BoxShape.circle,
color: Color.fromRGBO(0, 0, 0, 0.4),
//border: Border.all(color: Colors.black, width: 2.0),
),
child: InkWell(
onTap: () => showSettings(context),
child: Icon(
Icons.settings,
color: Colors.white,
),
),
),
),
)
],
),
_randomHeightWidgets(context),
TabBar(
labelStyle: TextStyle(
fontSize: SizeConfig.safeBlockHorizontal * 3,
),
controller: tabsController,
tabs: [
Tab(
text: "Posts",
),
Tab(
text: "Friends",
),
Tab(
text: "Recently Viewed",
),
],
),
],
),
),
body: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: ClassicHeader(),
controller: _refreshController,
onRefresh: _onRefresh,
child: TabBarView(
controller: tabsController,
children: [
Posts(),
Friends(),
Recently(),
],
),
),
);
}
}