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.

179 lines
5.6 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/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, required this.showSettings}) : super(key: key);
3 years ago
@override
_PersonnalState createState() =>
_PersonnalState(showSettings: this.showSettings);
}
enum AppBarBehavior { normal, pinned, floating, snapping }
class _PersonnalState extends State<Personnal> with TickerProviderStateMixin {
TesoUser? currentUser;
3 years ago
Function showSettings;
double? scale;
_PersonnalState({required this.showSettings});
double _appBarHeightSpecial = 270.0;
3 years ago
RefreshController _refreshController =
RefreshController(initialRefresh: false);
TabController? tabsController;
3 years ago
Widget _randomHeightWidgets(BuildContext context) {
return Consumer<UserProvider>(
builder: (BuildContext context, UserProvider user, Widget? child) {
3 years ago
user.getCurrentUser();
currentUser = user.currentUser;
if (user.currentUser == null || currentUser == null) {
return Container();
} else {
String dp = userdpURL + currentUser!.thumbnail_dp!;
3 years ago
return buildProfileHeader(
context,
currentUser!.gold!,
currentUser!.silver!,
currentUser!.username,
3 years ago
dp,
user.friends.isNotEmpty
3 years ago
? user.friends.length.toString()
: currentUser!.friends!,
currentUser!.firstname! + " " + currentUser!.lastname!,
3 years ago
_appBarHeightSpecial);
}
});
}
void _onRefresh() async {
Provider.of<UserProvider>(context, listen: false).getUserInformation();
switch (tabsController!.index) {
3 years ago
case 0:
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();
break;
default:
break;
}
_refreshController.refreshCompleted();
}
@override
void initState() {
super.initState();
3 years ago
tabsController = new TabController(length: 2, initialIndex: 0, vsync: this);
3 years ago
}
@override
void dispose() {
tabsController!.dispose();
3 years ago
_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) {
3 years ago
currentUser = user.currentUser;
if (user.currentUser == null || currentUser == null) {
return Container();
} else {
return Text(user.currentUser!.username!,
3 years ago
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: [
3 years ago
3 years ago
Tab(
text: "Friends",
),
Tab(
text: "Recently Viewed",
),
],
),
],
),
),
body: SmartRefresher(
enablePullDown: true,
enablePullUp: false,
header: ClassicHeader(),
controller: _refreshController,
onRefresh: _onRefresh,
child: TabBarView(
controller: tabsController,
children: [
Friends(),
Recently(),
],
),
),
);
}
}