I’ve Flutter software – easy on-line participant that makes use of flutter_carplay and audio_service. I launch this app to iOS solely.
- When the app begins, it hundreds gadgets that may be performed. This works as anticipated on cell gadget.
- In case I begin the app after which I flip it on by means of CarPlay as nicely, CarPlay display screen exhibits all gadgets appropriately.
- In case app will not be working and I open it solely by means of CarPlay, the display screen is empty. It appears to me that the app must be began first, earlier than it could actually work by means of CarPlay. Can any person advise the way to obtain this behaviour (so it may be began from CarPlay straight)? I consider it may be useful for a lot of builders, because the CarPlay performance in Flutter continues to be not documented nicely.
This the entry level of the app:
void major() async {
await App.initApp(); // primary initialization (Firebase, ...)
runApp(const App());
}
That is App
widget.
class App extends StatelessWidget {
const App({tremendous.key});
@override
Widget construct(BuildContext context) {
return MaterialApp(
builder: (BuildContext context, Widget? little one) {},
house: HomePage()
);
}
}
All of the CarPlay associated code could be present in HomePage
:
class HomePage extends StatefulWidget {
const HomePage({tremendous.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
closing FlutterCarplay _flutterCarplay = FlutterCarplay();
@override
void initState() {
tremendous.initState();
initCarPlay();
}
@override
Widget construct(BuildContext context) {
return ...;
}
void initCarPlay() {
FlutterCarplay.setRootTemplate(
rootTemplate: CPListTemplate(
sections: [
CPListSection(header: "Section 1", items: [
CPListItem(text: "Item 1"),
CPListItem(text: "Item 2"),
CPListItem(text: "Item 3"),
]),
CPListSection(header: "Part 2", gadgets: [
CPListItem(text: "Item 4"),
CPListItem(text: "Item 5"),
CPListItem(text: "Item 6"),
])
],
showsTabBadge: false,
systemIcon: "home.fill",
),
animated: true,
);
_flutterCarplay.forceUpdateRootTemplate();
_flutterCarplay.addListenerOnConnectionChange(_onCarplayConnectionChange);
}
void _onCarplayConnectionChange(CPConnectionStatusTypes standing) {
//
}
@override
void dispose() {
_flutterCarplay.removeListenerOnConnectionChange();
tremendous.dispose();
}
}
I’ve tried to name initCarPlay()
within the major()
straight, however the end result was the identical.