Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.01 KB | None | 0 0
  1. class _HomePageState extends State<HomePage> {
  2.  
  3. String username = 'user name';
  4. String userEmail = 'email address';
  5.  
  6. @override
  7. void initState() {
  8. super.initState();
  9. getCurrentUserName().then((value) {
  10. username = value;
  11. });
  12. getLanguage();
  13. }
  14.  
  15. String language;
  16. var refreshKey = GlobalKey<RefreshIndicatorState>();
  17. Map data;
  18.  
  19. String news;
  20. String signIn;
  21. List<Tab> tabs;
  22. ListView sideBarTabs;
  23.  
  24. Future<String> getCurrentUserName() {
  25. return new Future<String>.delayed(new Duration(milliseconds: 10000),() async {
  26. //Do a long running task. E.g. Network Call.
  27. final FirebaseUser currentUser = await _auth.currentUser();
  28. //assert(user.uid == currentUser.uid);
  29.  
  30. username = currentUser.displayName;
  31. return username;
  32. });
  33. }
  34.  
  35. Future getLanguage() async {
  36. SharedPreferences prefs = await SharedPreferences.getInstance();
  37. int lang = prefs.getInt('Language');
  38.  
  39. setState(() {
  40. if (lang != 1) {
  41. language = 'ku';
  42. news = 'هه‌وا';
  43. signIn = 'بچۆ ژووره‌وه‌';
  44. sideBarTabs = ListView(
  45. children: <Widget>[
  46. new UserAccountsDrawerHeader(
  47. accountName: Text(username),
  48. accountEmail: Text(userEmail),
  49. currentAccountPicture: GestureDetector(
  50. child: new CircleAvatar(
  51. backgroundColor: Colors.black,
  52. child: Icon(Icons.person),
  53. ),
  54. ),
  55. decoration: new BoxDecoration(
  56. color: Colors.pink,
  57. ),
  58. ),
  59. InkWell(
  60. onTap: () {
  61. var route = new MaterialPageRoute(
  62. builder: (BuildContext context) => new HomePage(),
  63. );
  64. Navigator.of(context).push(route);
  65. },
  66. child: ListTile(
  67. title: Text(news),
  68. leading: Icon(Icons.featured_play_list),
  69. )),
  70. InkWell(
  71. onTap: () {
  72. _SignInWithGoogle();
  73. },
  74. child: ListTile(
  75. title: Text(signIn),
  76. leading: Icon(Icons.person),
  77. )),
  78. ],
  79. );
  80. } else{
  81. language = 'ar';
  82. news = 'أخبار';
  83. signIn = 'تسجيل الدخول';
  84. sideBarTabs = ListView(
  85. children: <Widget>[
  86. new UserAccountsDrawerHeader(
  87. accountName: Text(username),
  88. accountEmail: Text(userEmail),
  89. currentAccountPicture: GestureDetector(
  90. child: new CircleAvatar(
  91. backgroundColor: Colors.black,
  92. child: Icon(Icons.person),
  93. ),
  94. ),
  95. decoration: new BoxDecoration(
  96. color: Colors.pink,
  97. ),
  98. ),
  99. InkWell(
  100. onTap: () {
  101. var route = new MaterialPageRoute(
  102. builder: (BuildContext context) => new HomePage(),
  103. );
  104. Navigator.of(context).push(route);
  105. },
  106. child: ListTile(
  107. title: Text(news),
  108. leading: Icon(Icons.featured_play_list),
  109. )),
  110. InkWell(
  111. onTap: () {
  112. _SignInWithGoogle();
  113. },
  114. child: ListTile(
  115. title: Text(signIn),
  116. leading: Icon(Icons.person),
  117. )),
  118. ],
  119. );
  120. }
  121. });
  122. }
  123.  
  124. Future<String> _SignInWithGoogle() async {
  125. final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
  126. final GoogleSignInAuthentication googleAuth =
  127. await googleUser.authentication;
  128. final AuthCredential credential = GoogleAuthProvider.getCredential(
  129. accessToken: googleAuth.accessToken,
  130. idToken: googleAuth.idToken,
  131. );
  132. final FirebaseUser user = await _auth.signInWithCredential(credential);
  133. assert(user.email != null);
  134. assert(user.displayName != null);
  135. assert(!user.isAnonymous);
  136. assert(await user.getIdToken() != null);
  137.  
  138. final FirebaseUser currentUser = await _auth.currentUser();
  139. assert(user.uid == currentUser.uid);
  140.  
  141. SharedPreferences prefs = await SharedPreferences.getInstance();
  142. prefs.setString('username', user.displayName);
  143. prefs.setString('useremail', user.email);
  144. //prefs.setString('IdToken', await user.getIdToken());
  145. }
  146.  
  147. @override
  148. Widget build(BuildContext context) {
  149. return MaterialApp(
  150. debugShowCheckedModeBanner: false,
  151. home: DefaultTabController(
  152. length: 9,
  153. child: Scaffold(
  154. appBar: new AppBar(
  155. bottom: TabBar(
  156. labelColor: Colors.black,
  157. isScrollable: true,
  158. tabs: tabs,
  159. ),
  160. iconTheme: new IconThemeData(color: Colors.black),
  161. backgroundColor: Colors.white,
  162. title: Text(
  163. "App Name",
  164. style: TextStyle(color: Colors.black),
  165. ),
  166. ),
  167. drawer: new Drawer(
  168. child: sideBarTabs,
  169. ),
  170.  
  171. class _HomePageState extends State<HomePage> {
  172.  
  173. String username = 'user name';
  174. String userEmail = 'email address';
  175.  
  176. @override
  177. void initState() {
  178. super.initState();
  179. getCurrentUserName().then((value) {
  180. username = value;
  181. });
  182. getLanguage();
  183. }
  184.  
  185. String language;
  186. var refreshKey = GlobalKey<RefreshIndicatorState>();
  187. Map data;
  188.  
  189. String news;
  190. String signIn;
  191. List<Tab> tabs;
  192. ListView sideBarTabs;
  193.  
  194. Future<String> getCurrentUserName() {
  195. return new Future<String>(() async{
  196. //Do a long running task. E.g. Network Call.
  197. SharedPreferences prefs = await SharedPreferences.getInstance();
  198.  
  199. username = prefs.getString('username');
  200. return username;
  201. });
  202. }
  203.  
  204. Future getLanguage() async {
  205. SharedPreferences prefs = await SharedPreferences.getInstance();
  206. int lang = prefs.getInt('Language');
  207.  
  208. setState(() {
  209. if (lang != 1) {
  210. language = 'ku';
  211.  
  212. news = 'هه‌وا';
  213. signIn = 'بچۆ ژووره‌وه‌';
  214.  
  215. sideBarTabs = ListView(
  216. children: <Widget>[
  217. new UserAccountsDrawerHeader(
  218. accountName: Text(username),
  219. accountEmail: Text(userEmail),
  220. currentAccountPicture: GestureDetector(
  221. child: new CircleAvatar(
  222. backgroundColor: Colors.black,
  223. child: Icon(Icons.person),
  224. ),
  225. ),
  226. decoration: new BoxDecoration(
  227. color: Colors.pink,
  228. ),
  229. ),
  230. InkWell(
  231. onTap: () {
  232. var route = new MaterialPageRoute(
  233. builder: (BuildContext context) => new HomePage(),
  234. );
  235. Navigator.of(context).push(route);
  236. },
  237. child: ListTile(
  238. title: Text(news),
  239. leading: Icon(Icons.featured_play_list),
  240. )),
  241. InkWell(
  242. onTap: () {
  243. _SignInWithGoogle();
  244. },
  245. child: ListTile(
  246. title: Text(signIn),
  247. leading: Icon(Icons.person),
  248. )),
  249. ],
  250. );
  251. } else{
  252. language = 'ar';
  253. news = 'أخبار';
  254. signIn = 'تسجيل الدخول';
  255. sideBarTabs = ListView(
  256. children: <Widget>[
  257. new UserAccountsDrawerHeader(
  258. accountName: Text(username),
  259. accountEmail: Text(userEmail),
  260. currentAccountPicture: GestureDetector(
  261. child: new CircleAvatar(
  262. backgroundColor: Colors.black,
  263. child: Icon(Icons.person),
  264. ),
  265. ),
  266. decoration: new BoxDecoration(
  267. color: Colors.pink,
  268. ),
  269. ),
  270. InkWell(
  271. onTap: () {
  272. var route = new MaterialPageRoute(
  273. builder: (BuildContext context) => new HomePage(),
  274. );
  275. Navigator.of(context).push(route);
  276. },
  277. child: ListTile(
  278. title: Text(news),
  279. leading: Icon(Icons.featured_play_list),
  280. )),
  281. InkWell(
  282. onTap: () {
  283. _SignInWithGoogle();
  284. },
  285. child: ListTile(
  286. title: Text(signIn),
  287. leading: Icon(Icons.person),
  288. )),
  289. ],
  290. );
  291. }
  292. });
  293. }
  294.  
  295. Future<String> _SignInWithGoogle() async {
  296. final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
  297. final GoogleSignInAuthentication googleAuth =
  298. await googleUser.authentication;
  299. final AuthCredential credential = GoogleAuthProvider.getCredential(
  300. accessToken: googleAuth.accessToken,
  301. idToken: googleAuth.idToken,
  302. );
  303. final FirebaseUser user = await _auth.signInWithCredential(credential);
  304. assert(user.email != null);
  305. assert(user.displayName != null);
  306. assert(!user.isAnonymous);
  307. assert(await user.getIdToken() != null);
  308.  
  309. final FirebaseUser currentUser = await _auth.currentUser();
  310. assert(user.uid == currentUser.uid);
  311.  
  312. SharedPreferences prefs = await SharedPreferences.getInstance();
  313. prefs.setString('username', user.displayName);
  314. prefs.setString('useremail', user.email);
  315. //prefs.setString('IdToken', await user.getIdToken());
  316. }
  317.  
  318.  
  319. @override
  320. Widget build(BuildContext context) {
  321. return MaterialApp(
  322. debugShowCheckedModeBanner: false,
  323. home: DefaultTabController(
  324. length: 9,
  325. child: Scaffold(
  326. appBar: new AppBar(
  327. bottom: TabBar(
  328. labelColor: Colors.black,
  329. isScrollable: true,
  330. tabs: tabs,
  331. ),
  332. iconTheme: new IconThemeData(color: Colors.black),
  333. backgroundColor: Colors.white,
  334. title: Text(
  335. "App Name",
  336. style: TextStyle(color: Colors.black),
  337. ),
  338. ),
  339. drawer: new Drawer(
  340. child: sideBarTabs,
  341. ),
  342.  
  343. class _HomePageState extends State<HomePage> {
  344.  
  345. String username = 'user name';
  346. String userEmail = 'email address';
  347.  
  348. @override
  349. void initState() {
  350. super.initState();
  351. getCurrentUser();
  352. getLanguage();
  353. }
  354.  
  355. String language;
  356. var refreshKey = GlobalKey<RefreshIndicatorState>();
  357. Map data;
  358.  
  359. String news;
  360. String signIn;
  361. List<Tab> tabs;
  362. ListView sideBarTabs;
  363.  
  364. Future<void> getCurrentUser() async{
  365. SharedPreferences prefs = await SharedPreferences.getInstance();
  366.  
  367. setState(() {
  368. if (_auth.currentUser() != null) {
  369. username = prefs.getString('username');
  370. userEmail = prefs.getString('useremail');
  371. } else{
  372. username = 'App name';
  373. userEmail = 'test@app.com';
  374. }
  375. });
  376. }
  377.  
  378. Future getLanguage() async {
  379. SharedPreferences prefs = await SharedPreferences.getInstance();
  380. int lang = prefs.getInt('Language');
  381.  
  382. setState(() {
  383. if (lang != 1) {
  384. language = 'ku';
  385. news = 'هه‌وا';
  386. signIn = 'بچۆ ژووره‌وه‌';
  387. sideBarTabs = ListView(
  388. children: <Widget>[
  389. new UserAccountsDrawerHeader(
  390. accountName: Text(username),
  391. accountEmail: Text(userEmail),
  392. currentAccountPicture: GestureDetector(
  393. child: new CircleAvatar(
  394. backgroundColor: Colors.black,
  395. child: Icon(Icons.person),
  396. ),
  397. ),
  398. decoration: new BoxDecoration(
  399. color: Colors.pink,
  400. ),
  401. ),
  402. InkWell(
  403. onTap: () {
  404. var route = new MaterialPageRoute(
  405. builder: (BuildContext context) => new HomePage(),
  406. );
  407. Navigator.of(context).push(route);
  408. },
  409. child: ListTile(
  410. title: Text(news),
  411. leading: Icon(Icons.featured_play_list),
  412. )),
  413. InkWell(
  414. onTap: () {
  415. _SignInWithGoogle();
  416. },
  417. child: ListTile(
  418. title: Text(signIn),
  419. leading: Icon(Icons.person),
  420. )),
  421. ],
  422. );
  423. } else{
  424. language = 'ar';
  425. news = 'أخبار';
  426. signIn = 'تسجيل الدخول';
  427. sideBarTabs = ListView(
  428. children: <Widget>[
  429. new UserAccountsDrawerHeader(
  430. accountName: Text(username),
  431. accountEmail: Text(userEmail),
  432. currentAccountPicture: GestureDetector(
  433. child: new CircleAvatar(
  434. backgroundColor: Colors.black,
  435. child: Icon(Icons.person),
  436. ),
  437. ),
  438. decoration: new BoxDecoration(
  439. color: Colors.pink,
  440. ),
  441. ),
  442. InkWell(
  443. onTap: () {
  444. var route = new MaterialPageRoute(
  445. builder: (BuildContext context) => new HomePage(),
  446. );
  447. Navigator.of(context).push(route);
  448. },
  449. child: ListTile(
  450. title: Text(news),
  451. leading: Icon(Icons.featured_play_list),
  452. )),
  453. InkWell(
  454. onTap: () {
  455. _SignInWithGoogle();
  456. },
  457. child: ListTile(
  458. title: Text(signIn),
  459. leading: Icon(Icons.person),
  460. )),
  461. ],
  462. );
  463. }
  464. });
  465.  
  466. }
  467.  
  468. Future<String> _SignInWithGoogle() async {
  469. final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
  470. final GoogleSignInAuthentication googleAuth =
  471. await googleUser.authentication;
  472. final AuthCredential credential = GoogleAuthProvider.getCredential(
  473. accessToken: googleAuth.accessToken,
  474. idToken: googleAuth.idToken,
  475. );
  476. final FirebaseUser user = await _auth.signInWithCredential(credential);
  477. assert(user.email != null);
  478. assert(user.displayName != null);
  479. assert(!user.isAnonymous);
  480. assert(await user.getIdToken() != null);
  481.  
  482. final FirebaseUser currentUser = await _auth.currentUser();
  483. assert(user.uid == currentUser.uid);
  484.  
  485. SharedPreferences prefs = await SharedPreferences.getInstance();
  486. prefs.setString('username', user.displayName);
  487. prefs.setString('useremail', user.email);
  488. //prefs.setString('IdToken', await user.getIdToken());
  489. }
  490.  
  491. @override
  492. Widget build(BuildContext context) {
  493. return MaterialApp(
  494. debugShowCheckedModeBanner: false,
  495. home: DefaultTabController(
  496. length: 9,
  497. child: Scaffold(
  498. appBar: new AppBar(
  499. bottom: TabBar(
  500. labelColor: Colors.black,
  501. isScrollable: true,
  502. tabs: tabs,
  503. ),
  504. iconTheme: new IconThemeData(color: Colors.black),
  505. backgroundColor: Colors.white,
  506. title: Text(
  507. "App Name",
  508. style: TextStyle(color: Colors.black),
  509. ),
  510. ),
  511. drawer: new Drawer(
  512. child: sideBarTabs,
  513. ),
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement