18.1 C
London
Monday, May 20, 2024

ios – Entry Flutter app from CarPlay display screen with out opening app first


I’ve Flutter utility – easy on-line participant that makes use of flutter_carplay and audio_service. I launch this app to iOS solely.

  1. When the app begins, it hundreds objects that may be performed. This works as anticipated on cellular gadget.
  2. In case I begin the app after which I flip it on by way of CarPlay as properly, CarPlay display screen reveals all objects accurately.
  3. In case app shouldn’t be working and I open it solely by way of CarPlay, the display screen is empty. It appears to me that the app must be began first, earlier than it could work by way of CarPlay. Can any person advise the right way to obtain this behaviour (so it may be began from CarPlay straight)? I imagine it may be useful for a lot of builders, because the CarPlay performance in Flutter continues to be not documented properly.

This the entry level of the app:

void major() async {
  await App.initApp(); // fundamental 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? baby) {},
        residence: 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> {
  last 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", objects: [
            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 outcome was the identical.

Latest news
Related news

LEAVE A REPLY

Please enter your comment!
Please enter your name here