Abdullah_mkr
Abdullah_mkr

Reputation: 11

How do I initialize one AppBar for ISO and Android?

I have tried to initialize the AppBar with PreferredSizeWidget, because otherwise in other Variables the PreferredSize gives an Error. If I initialize the AppBar with PreferredSizeWidget ich get the following Error:

lib/main.dart:96:9: Error: A value of type 'Widget' can't be assigned to a variable of type 'PreferredSizeWidget'.

  Widget build(BuildContext context) {
    final mediaQuery = MediaQuery.of(context);
    final isLandscape = mediaQuery.orientation == Orientation.landscape;
    final PreferredSizeWidget appBar = Platform.isIOS
        ? CupertinoNavigationBar(
            middle: Text('Personal Expenses'),
            trailing: Row(
              children: <Widget>[
                GestureDetector(
                  child: Icon(
                    CupertinoIcons.add,
                  ),
                  onTap: () => startAddNewTransaction(context),
                ),
              ],
            ),
          )
        : AppBar(
            title: Text('Expanse Planer'),
            actions: <Widget>[
              IconButton(
                icon: Icon(Icons.add),
                onPressed: () => startAddNewTransaction(context),
              )
            ],
          );
    final txListWidget = Container(
        height: (mediaQuery.size.height -
                appBar.PreferredSize.height -
                mediaQuery.padding.top) *
            0.7,
        child: TransactionList(_userTransaction, deletTransaction));

Upvotes: 0

Views: 178

Answers (1)

kk web
kk web

Reputation: 231

 -USE THIS CODE 
AppBar getAppBar(BuildContext context, String previousScreen, String? title,
    List<Widget> actions) {
  if (Platform.isAndroid) {
    return AppBar(
      brightness: Brightness.light,
      leading: GestureDetector(
        onTap: () {
          Navigator.pop(context);
        },
        child: Icon(
          Icons.arrow_back,
          color: kwhitecolor,
        ),
      ),
      title: Text(title!, style: ThemeText.appbarTitle),
      actions: actions,
     
      elevation: 1.0,
      shadowColor: Color(0xffdddddd),
    );
  } else {
    return AppBar(
       
      leadingWidth: 100,
      leading: GestureDetector(
        onTap: () {
          Navigator.pop(context);
        },
        child: Container(
          padding: EdgeInsets.only(left: 5.0),
          child: Row(
            children: [
              Icon(Icons.arrow_back_ios, ),
              Text(
                previousScreen,
                 
              ),
            ],
          ),
        ),
      ),
      title: Text(title!,  ),
      actions: actions,
       
      elevation: 1.0,
    );
  }
}

Upvotes: 0

Related Questions