带有菜单指示符的抽屉位于我在哪里的选项中

时间:2019-08-01 18:45:33

标签: flutter

我是新手,我遇到了问题,当我在其他页面中浏览时,尝试在我的抽屉中做一个菜单指示器会更改我所处选项的背景 示例https://montemagno.com/content/images/2017/07/compat1.png

我需要帮助:)

import 'dart:io';


import 'package:flutter/material.dart';
import 'package:news_app/pages/notes/index.dart';
import 'package:news_app/services/config-client.dart' as ConfigClient;
import 'package:url_launcher/url_launcher.dart';
import '../data/globals.dart';
import '../pages/vod/index.dart';

// import 'package:flutter_launch/flutter_launch.dart';

List<String> option_route =[
'/live_stream','/','/programs'
];

class DrawerItem{
  String title;
  IconData icon;
  DrawerItem(this.title, this.icon);
}

class MenuLeft extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return MenuState();
  }
}

class MenuState extends State<MenuLeft> {

    int _selectedIndex = 1;

    final draweritems = [
      DrawerItem('Live Stream', Icons.live_tv),
      DrawerItem('Noticias', Icons.receipt),
      DrawerItem('VOD', Icons.local_play)
    ];
   _getDrawerItemScreen(int pos) {
    return new NotesPage(drawerItem: draweritems[_selectedIndex]);
}


  _onSelected(int index) {
    setState(() {
      _selectedIndex = index;
      _getDrawerItemScreen(_selectedIndex);
    });
    Navigator.of(context).pop(); // close the drawer
}
  @override
  Widget build(BuildContext context) {


    return Theme(
      data: Theme.of(context).copyWith(
        // canvasColor: Colors.transparent,
        canvasColor: Theme.of(context).hintColor
      ),
      // data: Theme.of(context).hintColor,
      child: Drawer(
        child: _container(context),
      ),

    );
  }





  Widget _container(context) {
   List <Widget>drawerOptions = [];
     for (var i = 0; i < draweritems.length; i++) {
      var d = draweritems[i];
      drawerOptions.add(new Container(color: _selectedIndex != null && _selectedIndex == i  ? Theme.of(context).primaryColorDark : Colors.transparent,
        child:  
      ListTile(
        leading: new Icon(d.icon, color: Colors.white,),
        title: new Text(
          d.title,
          style: new TextStyle(fontSize: 18.0, fontWeight: FontWeight.w400, color: Colors.white),
        ),
        selected: i == _selectedIndex,
        onTap: ()  { 

          Navigator.pushNamed(context,option_route[i]);
          }
      ),));
}

    return Column(
      // color: Colors.white,
        children: <Widget>[
          // Divider(color: Colors.white,),
          DrawerHeader(
            // padding: EdgeInsets.only(bottom: 0.0),
            // padding: EdgeInsets.fromLTRB(0, 0,0,0),
            margin: EdgeInsets.symmetric(vertical: 0.0),
            // padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
            child: SafeArea(
              child: Column(
                mainAxisAlignment:  MainAxisAlignment.spaceAround,
                crossAxisAlignment: CrossAxisAlignment.center,
                // mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  _imgUserTop(context),
                  Padding(
                    padding: const EdgeInsets.symmetric(vertical: 2.0),
                    child: DefaultTextStyle(
                      style: Theme.of(context).primaryTextTheme.body2,
                      overflow: TextOverflow.ellipsis,
                      child: Text(ConfigClient.tenantName),
                    ),
                  ),
                ],
              ),
            )
          ),

          Divider(color: Colors.white),
          Expanded(
            child: ListView(children: <Widget>[Column(children: drawerOptions)],)

              // child: ListView(
              //   children: optionsMenu(context)
              // )

          ),
          Divider(color: Colors.white),
          // Expanded(
          //   child: Column(
          //     children: optionsMenu(context)
          //   )
          // ),
          //   child: Container(
          //     child: ListView(
          //       children: <Widget>[
          //       ],
          //     ),
          //   ),

          // ),
          Container(
            // margin: EdgeInsets.all(16),
            child: Wrap(
              children: <Widget>[
                GestureDetector(
                  onTap: (){
                    _openFb();
                  },
                  child: buttonSocial("assets/social/whites/fb.png"),
                ),
                GestureDetector(
                  onTap: (){
                    _openTwitter();
                  },
                  child: buttonSocial("assets/social/whites/tw.png"),
                ),
                GestureDetector(
                  onTap: (){
                    _openMail();
                    // FlutterLaunch.launchWathsApp(phone: "5219982145900", message: "Hello");
                    // FlutterLaunch.hasApp()
                  },
                  child: buttonSocial("assets/social/whites/mail.png"),
                ),
                GestureDetector(
                  onTap: (){
                    // FlutterLaunch.launchWathsApp(phone: "5219982145900", message: "Hello");
                    // FlutterLaunch.hasApp()
                    _openWhatsapp();
                  },
                  child: buttonSocial("assets/social/whites/wt.png"),
                ),  
              ],
            ),
          ),
          // socialButtons()
        ],
    );
  }

  Widget _imgUserTop(context){
    return Semantics(
      explicitChildNodes: true,
      child: SizedBox(
        width: 72,
        height: 72,
        child: CircleAvatar(
          backgroundColor: Colors.transparent,
          // backgroundColor: Theme.of(context).platform == TargetPlatform.iOS
          //     ? Colors.blue
          //     // : Colors.white,
          //     : Colors.transparent ,
          child: Image.asset("assets/Logo_app.png")
        ),
      )
    );
  }


  List<Widget> optionsMenu(context){
    return [
      ListTile(
        leading: Icon(
          Icons.live_tv,
          color: Colors.white,
        ),
        title: Text(
          "Live Stream",
          style: TextStyle(color: Colors.white),
        ),
        onTap: () {
          Navigator.pushNamed(context, '/live_stream');
        },
      ),

      ListTile(
        leading: Icon(
          Icons.receipt,
          color: Colors.white,
        ),
        title: Text(
          'Noticias',
          style: TextStyle(color: Colors.white),
        ),
        onTap: () {
          Navigator.pushReplacementNamed(context, '/');
        },
      ),
      ListTile(
        leading: Icon(
          Icons.local_play,
          color: Colors.white,
        ),
        title: Text(
          "VOD",
          style: TextStyle(color: Colors.white),
        ),
        onTap: () {
          Navigator.pushReplacementNamed(context, '/programs');
        },
      )
    ];
  }

  Widget buttonSocial(String imgAsset){
    return 
      Container(
        margin: EdgeInsets.symmetric(vertical: 12,horizontal: 15),
        height: 30,
        width: 30,
        decoration: BoxDecoration(
            image: DecorationImage(
          image: AssetImage(imgAsset),
        )),
    );
  }

  _openFb() async{
    const url = "fb://page/394743943987615";
    if (Platform.isIOS) {
      // AppAvailability.launchApp("com.facebook.katana");
      // com.facebook.lite
      await launch(url);
    }
    if (await canLaunch(url)) {
      await launch(url);
      // AppAvailability.launchApp("fb://profile/394743943987615");
    }
  }
  _openWhatsapp() async{
    print("hola whatsapp ->");
    var whatsappUrl ="whatsapp://send?phone=529983214782";
    await canLaunch(whatsappUrl)? launch(whatsappUrl):print("open whatsapp app link or do a snackbar with notification that there is no whatsapp installed");

  }

  _openTwitter() async{
    // window.open('twitter:///user?screen_name=Tucanal10', '_system')
    if (Platform.isAndroid) {
      try {
        await launch("https://twitter.com/Tucanal10");
      } catch (e) {
        print("No se pudo abrir flutter en el navegador.");
      }
    } else {
      await launch("twitter:///user?screen_name=Tucanal10");
    }
  }

  _openMail() async{
    // if (Platform.isIOS) {
    await launch("mailto:info@canal10.tv?subject=Información&body=A%20quien%20corresponda");  
    // }
    // if (Platform.isAndroid) {
    //   await launch("mailto:smith@example.org?subject=News&body=New%20plugin");
    // }
    // mailto:<email address>?subject=<subject>&body=<body>, e.g. 
    // mailto:smith@example.org?subject=News&body=New%20plugin  
  }
}

在我的代码中,触摸选项时更改颜色,但我不需要

0 个答案:

没有答案