Here is my main.dart Code
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:window_manager/window_manager.dart';
import 'package:agiler/providers/auth_screen_provider.dart';
import 'package:agiler/providers/home_screen_provider.dart';
import 'package:agiler/utilities/app_strings/app_strings.dart';
import 'package:agiler/initialization_main/main_initialization.dart';
import 'dart:developer';
import 'dart:ffi' as ffi;
import 'package:ffi/ffi.dart';
import 'package:dylib/dylib.dart' as dlib;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
windowManager.setSkipTaskbar(true);
await windowManager.ensureInitialized();
await MainInitializer.initWindowManager();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({super.key});
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
@override
Widget build(BuildContext context) {
return MultiProvider(
providers:[
ChangeNotifierProvider(create: (_) => HomeScreenProvider()),
ChangeNotifierProvider(create: (_) => AuthScreenProvider()),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
navigatorKey: navigatorKey,
title: MyAppString.appTitle,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const Sample(),
// home: const SplashScreen(),
),
);
}
}
typedef StartFunc = ffi.Void Function();
typedef Start = void Function();
typedef StopFunc = ffi.Void Function();
typedef Stop = void Function();
final dylib = ffi.DynamicLibrary.open('main.dylib');
final Start start =
dylib.lookup<ffi.NativeFunction<StartFunc>>('Start').asFunction();
final Stop stop =
dylib.lookup<ffi.NativeFunction<StopFunc>>('Stop').asFunction();
class Sample extends StatelessWidget {
const Sample({super.key});
@override
Widget build(BuildContext context) {
debugPrint("Build Passed");
return Scaffold(
body: Center(child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: (){
debugPrint("Start");
start;
},
child: const Text("Start")),
ElevatedButton(
onPressed: (){
debugPrint("Stop");
stop;
},
child: const Text("Stop")),
],
),),
);
}
}
Here is my go_code
package main
import "C"
import (
"fmt"
"log"
)
//export Start
func Start() {
log.Println("My Go Code Start run successfully")
}
//export Stop
func Stop() {
log.Printf("My Go Code Stop run successfully")
}
func main() {
fmt.Printf("My Go Code Main run successfully\n")
Start()
Stop()
}
There was an issue came Failed to load library but now the issue is resolved.
After that I got an error of Failed to lookup symbol of Start and Stop. Again this is resolved.
Now there is no any issue showing but on tapping the button of stop and start in dart. There is no any line print by the go code. But the problem is that there is no any connection between go code and flutter I have tried all the method given by the codelabs still not works.
I want to connecting the flutter with the golang So that we run our app in the background. But stucking on the connnection between golang with flutter.
I have also tried the
go build -o main.dylib -buildmode=c-shared main.go
for creating the .dylib folder after running the main.go file.
Please anyone help me
start;need to bestart();?