Browse Source

fix Bug #7348

master
daivph 5 years ago
parent
commit
c9bdaede07
2 changed files with 40 additions and 1 deletions
  1. +23
    -0
      lib/presentation/screens/slide_menu/drawer_user_controller.dart
  2. +17
    -1
      lib/presentation/screens/slide_menu/home_drawer.dart

+ 23
- 0
lib/presentation/screens/slide_menu/drawer_user_controller.dart View File

import 'package:farm_tpf/data/repository/user_repository.dart';
import 'package:farm_tpf/utils/const_color.dart'; import 'package:farm_tpf/utils/const_color.dart';
import 'package:farm_tpf/utils/pref.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart';


import 'home_drawer.dart'; import 'home_drawer.dart';


ScrollController scrollController; ScrollController scrollController;
AnimationController iconAnimationController; AnimationController iconAnimationController;
AnimationController animationController; AnimationController animationController;
UserRepository _userRepository = UserRepository();


double scrolloffset = 0.0; double scrolloffset = 0.0;
var pref = LocalPref();
final updateFullName = Get.put(UpdateFullName());


@override @override
void initState() { void initState() {
} }


void onDrawerClick() { void onDrawerClick() {
getSharedPrefs();
//if scrollcontroller.offset != 0.0 then we set to closed the drawer(with animation to offset zero position) if is not 1 then open the drawer //if scrollcontroller.offset != 0.0 then we set to closed the drawer(with animation to offset zero position) if is not 1 then open the drawer
if (scrollController.offset != 0.0) { if (scrollController.offset != 0.0) {
scrollController.animateTo( scrollController.animateTo(
); );
} }
} }

Future<Null> getSharedPrefs() async {
try {
updateFullName.init();
var currentFullName = await pref.getString(DATA_CONST.CURRENT_FULL_NAME);
if (currentFullName.isEmpty) {
var currentUser = await _userRepository.getUser();
pref.saveString(DATA_CONST.CURRENT_FULL_NAME, currentUser.fullName);
updateFullName.changeName(currentUser.fullName);
} else {
updateFullName.changeName(currentFullName);
}
} catch (e) {
print("error: ${e.toString()}");
}
}
} }

+ 17
- 1
lib/presentation/screens/slide_menu/home_drawer.dart View File

import 'package:farm_tpf/utils/pref.dart'; import 'package:farm_tpf/utils/pref.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get/get.dart';
import 'package:get/state_manager.dart';


class HomeDrawer extends StatefulWidget { class HomeDrawer extends StatefulWidget {
const HomeDrawer( const HomeDrawer(
var pref = LocalPref(); var pref = LocalPref();
UserRepository _userRepository = UserRepository(); UserRepository _userRepository = UserRepository();
List<DrawerList> drawerList; List<DrawerList> drawerList;
final updateFullName = Get.put(UpdateFullName());

@override @override
void initState() { void initState() {
setdDrawerListArray(); setdDrawerListArray();
Padding( Padding(
padding: const EdgeInsets.only(top: 8, left: 20), padding: const EdgeInsets.only(top: 8, left: 20),
child: Text( child: Text(
'Võ Phước Đại',
'${Get.find<UpdateFullName>().fullName ?? ''}',
style: TextStyle( style: TextStyle(
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: COLOR_CONST.GRAY1, color: COLOR_CONST.GRAY1,
String imageName; String imageName;
DrawerIndex index; DrawerIndex index;
} }

class UpdateFullName extends GetxController {
var fullName;
void init() {
fullName = "";
}

void changeName(String name) {
fullName = name;
update();
}
}

Loading…
Cancel
Save