Si te muestra el siguiente error:
The body might complete normally, causing ‘null’ to be returned, but the return type is a potentially non-nullable type. Try adding either a return or a throw statement at the end.
Necesitas agregarle al final un default y retornar tu vista por ejemplo Home:
De esta manera quedó mi switch
switch (index) {
case 0:
return CupertinoTabView(
builder: (BuildContext context) => Home(),
);
case 1:
return CupertinoTabView(
builder: (BuildContext context) => Search(),
);
case 2:
return CupertinoTabView(
builder: (BuildContext context) => Profile(),
);
default:
return CupertinoTabView(
builder: (BuildContext context) => Home(),
);
}
Código completo aquí, presentará algunas variaciones
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'home.dart';
import 'search.dart';
import 'profile.dart';
class NavifationBarCupertinoIos extends StatelessWidget {
@override
Widget build(BuildContext context) {
// ignore: todo
// TODO: implement build
return Scaffold(
bottomNavigationBar: CupertinoTabScaffold(
tabBar: CupertinoTabBar(items: [
BottomNavigationBarItem(
icon: Icon(Icons.home, color: Colors.indigo), label: ""),
BottomNavigationBarItem(
icon: Icon(Icons.search, color: Colors.indigo), label: ""),
BottomNavigationBarItem(
icon: Icon(Icons.person, color: Colors.indigo), label: ""),
]),
tabBuilder: (BuildContext context, int index) {
switch (index) {
case 0:
return CupertinoTabView(
builder: (BuildContext context) => Home(),
);
case 1:
return CupertinoTabView(
builder: (BuildContext context) => Search(),
);
case 2:
return CupertinoTabView(
builder: (BuildContext context) => Profile(),
);
default:
return CupertinoTabView(
builder: (BuildContext context) => Home(),
);
}
},
),
);
}
}
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?