Flutter Webview在单击功能的抽屉式导航中不起作用

时间:2019-12-13 06:01:56

标签: android ios flutter dart flutter-layout

我试图在flutter中使用webview,在抽屉式导航列表项的onclick方法上使用它。但这没用。我使用的代码是

onclick(){ 
  webview( 
     initalurl: 'hhtp//www.google.com'
   )
}

如果有人可以帮助我,请

1 个答案:

答案 0 :(得分:0)

Here is the Code, I have used Navigator rather than Webview just because that was not working. I have used at one place where you can see the way I was using Webiew in Drawer Navigator .
class BottomNavBar extends StatefulWidget {
  @override
  _BottomNavBarState createState() => _BottomNavBarState();
}

class _BottomNavBarState extends State<BottomNavBar> {
  int _page = 0;
  GlobalKey _bottomNavigationKey = GlobalKey();
// ignore: non_constant_identifier_names
final Tab=[
  WebViewContainer('https://panel.islamlive.app'),
  messages(),
  WebViewContainer('https://panel.islamlive.app/my-account/all-notifications/'),
  dashbord(),
  WebViewContainer('https://panel.islamlive.app/user/buyer/'),
];
@override

  @override
  Widget build(BuildContext context) {
    void page(){
      Navigator.of(context).pop();
      Navigator.push(context,
                         new MaterialPageRoute(builder: (context) => homrpage()));
    }
    return Scaffold(
      appBar: AppBar(title: Image(image: AssetImage('assets/logo.png')),backgroundColor: Colors.lightGreen,),
      body: Tab[_page],
      drawer: new Drawer(
        elevation: 3.0,
        child: ListView(
          children: <Widget>[
            ListTile(
                title: Text("List New Service"),
                trailing: new Icon(Icons.local_laundry_service),
                onTap:()=>{
                  WebView(initialUrl: 'https://panel.islamlive.app',)
                 // Navigator.push(context, new MaterialPageRoute(builder: (context)=>ListNewService()))
                }
                ),
            new Divider(),
            ListTile(
              title: Text("Manage Listings"),
              trailing: new Icon(Icons.hearing),
              onTap: ()=>{
                Navigator.push(context, new MaterialPageRoute(builder: (context)=>ManageListning()))
              },
              ),
            new Divider(),
            ListTile(
              title: Text('Manage Calendar'),
              trailing: new Icon(Icons.calendar_today),
              onTap: ()=>{
                Navigator.push(context, new MaterialPageRoute(builder: (context)=>ManageCalender()))
              },
              ),
            new Divider(),
            ListTile(
              title: Text("Service Requests"),
              trailing: new Icon(Icons.room_service),
              onTap: ()=>{
                Navigator.push(context,new MaterialPageRoute(builder: (context)=>ServiceRequest()))
              },
              ),
            new Divider(),
            ListTile(
              title: Text("Confirmed Appointments"),
              trailing: new Icon(Icons.confirmation_number),
              onTap: ()=>{
                 Navigator.push(context,new MaterialPageRoute(builder: (context)=>CconfirmedAppointment()))
              },
              ),
            new Divider(),
            ListTile(
              title: Text("Pending Confirmation"),
              trailing: new Icon(Icons.today),
              onTap: ()=>{
                 Navigator.push(context,new MaterialPageRoute(builder: (context)=>PendingConfirmation()))
              },
              ),
            new Divider(),
            ListTile(
              title: Text("Earnings"),
              trailing: new Icon(Icons.work),
              onTap: ()=>{
                Navigator.push(context,new MaterialPageRoute(builder: (context)=>Earnings()))
              },
              ),
            ListTile(
              title: Text("Student Menu"),
              subtitle: Text("Post Service Request"),
              trailing: new Icon(Icons.directions_run),
              onTap: ()=>{
                Navigator.push(context,new MaterialPageRoute(builder: (context)=>StudentMenu()))
              },
              ),
            new Divider(),
            ListTile(
              title: Text("Transactions"),
              trailing: new Icon(Icons.transit_enterexit),
              onTap: ()=>{
                Navigator.push(context,new MaterialPageRoute(builder: (context)=>Transactions()))
              },
              ),
            new Divider(),
            ListTile(
              title: Text("My Favorites"),
              trailing: new Icon(Icons.favorite),
              onTap: ()=>{
                Navigator.push(context,new MaterialPageRoute(builder: (context)=>MyFavorite()))
              },
              ),
            new Divider(),
            ListTile(
              title: Text("Settings"),
              trailing: new Icon(Icons.settings),
              onTap: ()=>{
                Navigator.push(context,new MaterialPageRoute(builder: (context)=>Settings()))
              },
              ),
            new Divider(),
            ListTile(
              title: Text("Logout"),
              trailing: new Icon(Icons.exit_to_app),
              onTap: ()=>{
                WebView(
                  initialUrl: 'https://panel.islamlive.app/wp-login.php?action=logout&redirect_to=https%3A%2F%2Fpanel.islamlive.app&_wpnonce=8f283f4fe9',
                )
              },
              ),
          ],
          ),
        ),
        bottomNavigationBar: CurvedNavigationBar(
          key: _bottomNavigationKey,
          index: _page,
          height: 40.0,
          items: <Widget>[
            Icon(Icons.home, size: 30),
            Icon(Icons.message, size: 30),
            Icon(Icons.notifications_active, size: 30),
            Icon(Icons.dashboard, size: 30),
            Icon(Icons.verified_user, size: 30),
          ],
          color: Colors.lightGreen,
          buttonBackgroundColor: Colors.lightGreen,
          backgroundColor: Colors.white,
          animationCurve: Curves.easeInOut,
          animationDuration: Duration(milliseconds: 200),
          onTap: (index) {
            setState(() {
              _page = index;
            });
          },
          ),
        );
  }
}