flutter_app/lib/main.dart

122 lines
4.0 KiB
Dart
Raw Normal View History

import 'dart:ffi';
import 'package:ffi/ffi.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'model.dart';
import 'views/profilemgrview.dart';
import 'package:flutter/services.dart';
import 'dart:io' show Platform;
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'model.dart' as model;
import 'dart:collection';
import 'dart:convert';
import 'package:flutter/material.dart';
typedef start_cwtch_function = Void Function(Pointer<Utf8> str, Int32 length);
typedef StartCwtchFn = void Function(Pointer<Utf8> dir, int len);
typedef access_cwtch_eventbus_function = Void Function();
typedef NextEventFn = void Function();
typedef get_json_blob_void_function = Pointer<Utf8> Function();
typedef GetJsonBlobVoidFn = Pointer<Utf8> Function();
typedef get_json_blob_string_function = Pointer<Utf8> Function(Pointer<Utf8> str, Int32 length);
typedef GetJsonBlobStringFn = Pointer<Utf8> Function(Pointer<Utf8> str,int len);
void main() => runApp(Flwtch());
class Flwtch extends StatefulWidget {
final Key flwtch = GlobalKey();
@override
FlwtchState createState() => FlwtchState();
}
class FlwtchState extends State<Flwtch> {
final TextStyle biggerFont = const TextStyle(fontSize: 18);
DynamicLibrary library;
AppModel appStatus;
static const appInfoPlatform = const MethodChannel('test.flutter.dev/applicationInfo');
var androidLibraryDir = "";
var androidHomeDirectory = "";
@override
initState() {
super.initState();
if (Platform.isAndroid) {
getApplicationDocumentsDirectory().then((directory) =>
{
setState(() {
print("androidHomeDir = $directory");
androidHomeDirectory = directory.path;
})
});
appInfoPlatform.invokeMethod('getNativeLibDir').then((value) =>
{
setState(() {
print("nativeLibraryDir = $value");
androidLibraryDir = value;
})
});
}
}
@override
Widget build(BuildContext context) {
library = DynamicLibrary.open("libCwtch.so");
appStatus = AppModel(library: library);
String home = "";
Map<String, String> envVars = Platform.environment;
if (Platform.isMacOS) {
home = envVars['HOME'];
} else if (Platform.isLinux) {
home = envVars['HOME'];
} else if (Platform.isWindows) {
home = envVars['UserProfile'];
} else if (Platform.isAndroid) {
home = androidHomeDirectory;
}
var startCwtchC = library.lookup<NativeFunction<start_cwtch_function>>("StartCwtch");
// ignore: non_constant_identifier_names
final StartCwtch = startCwtchC.asFunction<StartCwtchFn>();
var cwtchDir = path.join(home, ".cwtch/dev/");
print("cwtchDir $cwtchDir");
StartCwtch(Utf8.toUtf8(cwtchDir), cwtchDir.length);
return Provider<FlwtchState>(
create: (_) => this,
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
primaryColor: Color(0xFF4B3557),
canvasColor: Color(0xFFB09CBC),
accentColor: Color(0xFFD01972),
),
home: ProfileMgrView(),
));
}
}