Advertisement
Guest User

Untitled

a guest
Apr 11th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 3.74 KB | None | 0 0
  1.  class _ParentWidgetState extends State<MainFeedPage> with AfterLayoutMixin<MainFeedPage>{
  2.     String empName;
  3.     Future<List> getUserData() async{
  4.       final response = await http.post("http://172.16.161.34:8080/ebs/cfs/android_test_app/accessfile.php?q=getUserData",body:{
  5.       "emp_id": widget.empId,
  6.       });
  7.       var dataUser = jsonDecode(response.body);
  8.       empName = dataUser[0]['name'];
  9.  
  10.       return null;
  11.     }
  12.  
  13.     @override
  14.   void initState() {
  15.     super.initState();
  16.     BackButtonInterceptor.add(myInterceptor);
  17.   }
  18.  
  19.   @override
  20.   void dispose() {
  21.     BackButtonInterceptor.remove(myInterceptor);
  22.     super.dispose();
  23.   }
  24.  
  25.     bool myInterceptor(bool stopDefaultButtonEvent) {
  26.     //print("BACK BUTTON!"); // Do some stuff.
  27.     return true;
  28.   }
  29.  
  30.     @override
  31.     void afterFirstLayout(BuildContext context) {
  32.       // Calling the same function "after layout" to resolve the issue.
  33.       getUserData();
  34.     }
  35.  
  36.   @override
  37.   Widget build(BuildContext context) {
  38.     // TODO: implement build
  39.     return new MaterialApp(
  40.       title: 'ALTURAS TEST APP',
  41.       debugShowCheckedModeBanner: false,
  42.       color: Colors.white,
  43.       home: DefaultTabController(
  44.         length: 3,
  45.         child: new Scaffold(
  46.           appBar: AppBar(
  47.             iconTheme: new IconThemeData(color: Colors.black ),
  48.             textTheme: TextTheme(
  49.                 title: TextStyle(
  50.                   color: Colors.black,
  51.                 )
  52.             ),
  53.             title: Text(empName),
  54.             backgroundColor: Colors.white,
  55.             actions: <Widget>[
  56.               IconButton(icon: Icon(Icons.shopping_cart),onPressed:(){
  57.                 getUserData();
  58.               },),
  59.               IconButton(icon: Icon(Icons.person),onPressed:(){},),
  60.             ],
  61.             elevation: 0.0,
  62.           ),
  63.           drawer: Drawer(
  64.  
  65.             child: ListView(
  66.               // Important: Remove any padding from the ListView.
  67.               padding: EdgeInsets.zero,
  68.               children: <Widget>[
  69.                 DrawerHeader(
  70.                   child: Text(''),
  71.                   decoration: BoxDecoration(
  72.                     color: Colors.white,
  73.                   ),
  74.                 ),
  75.                 ListTile(
  76.                   title: Text('Item 1'),
  77.                   onTap: () {
  78.                     // Update the state of the app
  79.                     // ...
  80.                   },
  81.                 ),
  82.                 ListTile(
  83.                   title: Text('Item 2'),
  84.                   onTap: () {
  85.                     // Update the state of the app
  86.                     // ...
  87.                   },
  88.                 ),
  89.               ],
  90.             ),
  91.  
  92.           ),
  93.           body: new TabBarView(
  94.             physics: NeverScrollableScrollPhysics(),
  95.             children :<Widget>[
  96.               new Screen1(),
  97.               new Screen2(),
  98.               new Screen3()
  99.             ],
  100.           ),
  101.           bottomNavigationBar: new TabBar(
  102.  
  103.             tabs: [
  104.               Tab(
  105.                 text: "Home",
  106.                 icon: new Icon(Icons.home,),
  107.               ),
  108.               Tab(
  109.                 text: "Profile",
  110.                 icon: new Icon(Icons.perm_identity),
  111.               ),
  112.               Tab(
  113.                 text: "Settings",
  114.                 icon: new Icon(Icons.settings),
  115.               )
  116.             ],
  117.             labelStyle: TextStyle(fontSize: 12.0),
  118.             labelColor: Colors.black,
  119.             unselectedLabelColor: Colors.black38,
  120.             indicatorSize: TabBarIndicatorSize.label,
  121.             indicatorPadding: EdgeInsets.all(1.0),
  122.             indicatorColor: Colors.black,
  123.           ),
  124.           backgroundColor: Colors.white,
  125.         ),
  126.       ),
  127.     );
  128.   }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement