import '../screens/category_screen.dart'; import '../utils/const.dart'; import '../widgets/card_courses.dart'; import '../widgets/header.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'dart:convert'; import 'SelectClass.dart'; import 'SelectPage.dart'; import '../../home/select_subject.dart'; import 'category_screen.dart'; class HomeScreen extends StatefulWidget { @override _HomeScreenState createState() => _HomeScreenState(); } class _HomeScreenState extends State { final TextEditingController _searchControl =TextEditingController(); FocusNode myFocusNode; String userfullname = ''; @override void initState() { getData().then((value) => {''}); super.initState(); myFocusNode = FocusNode(); } Future CategoryStorage(id) async { if (id == '10' || id == '11') { var route = new MaterialPageRoute( builder: (BuildContext context) => new SelectClassPage(value: id), ); Navigator.of(context).push(route); } else if (id == '12') { var route = new MaterialPageRoute( builder: (BuildContext context) => new NextPage(value: id), ); Navigator.of(context).push(route); } else { // this function will set the storage of category id SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.setString('categoryid', id); Navigator.push( context, MaterialPageRoute( builder: (context) => SelectSubject(), )); } } Future getData() async { SharedPreferences prefs = await SharedPreferences.getInstance(); var fullname = prefs.getString('userfullname'); var cat = prefs.getString('cat'); var decoded = json.decode(cat); setState(() { userfullname = fullname; }); return fullname; } var fullname = ''; Future saveDetails() async { SharedPreferences prefs = await SharedPreferences.getInstance(); var getstr = prefs.getString('fullname'); fullname = getstr; return getstr; } @override void dispose() { _searchControl.dispose(); myFocusNode.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( extendBodyBehindAppBar: true, appBar: PreferredSize( preferredSize: Size(double.infinity, 100), child: SafeArea( child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ Container( margin:EdgeInsets.symmetric( horizontal: Constants.mainPadding, vertical: Constants.mainPadding ), height: 44, width: 44, child: Builder( builder: (ctx) => FlatButton( padding: EdgeInsets.all(0), color: Colors.white.withOpacity(0.3), child: Icon(Icons.menu, color: Colors.white), shape:RoundedRectangleBorder( borderRadius:BorderRadius.circular(10.0), ), onPressed: () {Scaffold.of(ctx).openDrawer(); }, ), ), ), ], ), ), ), drawer:Drawer( child:ListView( children: [ Container(child: Padding( padding: const EdgeInsets.all(30.0), child:Image.asset('assets/images/education.png'), ),color: Color(0xFFf0f0f0),) , ListTile( leading:Icon(Icons.photo), title:Text("Photo"), onTap: () { // Navigator.pop(context); // Navigator.of(context).pushNamed(PHOTO_CONTAINER_SCREEN); }, ), ListTile( leading:Icon(Icons.video_library), title:Text("Video"), onTap: () { // Navigator.pop(context); // Navigator.of(context).pushNamed(VIDEO_CONTAINER_SCREEN); }, ), ListTile( leading:Icon(Icons.photo_library), title:Text("Album"), onTap: () { // Navigator.pop(context); // Navigator.of(context).pushNamed(ALBUM_CONTAINER_SCREEN); }, ) ], )), body: Stack( children: [ Header(), Padding( padding: EdgeInsets.all(Constants.mainPadding), child: ListView( scrollDirection: Axis.vertical, children: [ SizedBox(height: Constants.mainPadding * 2), // 1. Welcome User Text("Welcome back", style: TextStyle( fontSize: 34, fontWeight: FontWeight.w900, color: Colors.white ), ), SizedBox(height: 5), Text("$userfullname", style: TextStyle( fontSize: 18, fontWeight: FontWeight.w700, color: Colors.grey[300] ), ), SizedBox(height: Constants.mainPadding), // 3. Start Learning Button Section Stack( children: [ Container( width: double.infinity, padding: EdgeInsets.all(30.0), decoration: BoxDecoration( borderRadius: BorderRadius.circular(30.0), color: Color(0xFFFEF3F3), ), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start, children: [ Text("Start Learning \nNew Stuff!", style: TextStyle( fontSize: 20, fontWeight: FontWeight.bold, color: Constants.textDark ), ), SizedBox(height: 10.0), // Categories Button Container( width: 150, child: FlatButton( padding: EdgeInsets.all(10.0), color: Constants.salmonMain, child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ Expanded( child: Center( child: Text("Subscribe", style: TextStyle( color: Colors.white ), ), ), ), Icon(Icons.arrow_forward, color: Colors.white, size: 16), ], ), shape:RoundedRectangleBorder( borderRadius:BorderRadius.circular(13.0), ), onPressed: () { // Navigate to Learning debugPrint("Pressed here"); Navigator.push( context, MaterialPageRoute(builder: (context) => CategoryScreen()), ); }, ), ) ], ), ), // Image Researching Girl Positioned( right: 0, bottom: 0, child: Image.asset("assets/images/researching.png", width: 200, height: 104, ), ), ], ), SizedBox(height: 20.0), Text("Courses and Materials", style: TextStyle( color: Constants.textDark, fontSize: 18, fontWeight: FontWeight.bold, ) ), SizedBox(height: 20.0), // List of courses ListView( scrollDirection: Axis.vertical, physics: NeverScrollableScrollPhysics(), shrinkWrap: true, children: [ GestureDetector( onTap: () => CategoryStorage('20'), child: CardCourses( image: Image.asset("images/management.png", width: 40, height: 40), color: Constants.lightPink, title: "100L Tutorials", content: 'Access unlimited videos to prepare students preparing for 100L examinations', ), ), CardCourses( image: Image.asset('images/study.png', width: 40, height: 40), color: Constants.lightPink, title: 'P-UTME Tutorials', content: 'Access unlimited videos to prepare students preparing for P-UTME examinations', ), CardCourses( image: Image.asset('images/waec.png', width: 40, height: 40), color: Constants.lightPink, title: 'S.S.C.E Tutorials', content: 'Access unlimited videos to prepare students preparing for S.S.C.E examinations', ), CardCourses( image: Image.asset('images/jamb.png', width: 40, height: 40), color: Constants.lightPink, title: 'J.A.M.B Tutorials', content: 'Access unlimited videos to prepare students preparing for J.A.M.B examinations', ), CardCourses( image: Image.asset('images/school.png', width: 40, height: 40), color: Constants.lightPink, title: 'Senior Secondary', content: 'Access unlimited videos to prepare students preparing for Senior Secondary examinations', ), ], ), ], ), ), ], ), ); } }