2021-01-13 23:17:02 +00:00
|
|
|
import 'dart:collection';
|
|
|
|
import 'dart:convert';
|
|
|
|
|
2021-01-12 06:21:18 +00:00
|
|
|
import 'package:flutter_app/cwtch/ffi.dart';
|
2021-01-13 05:47:20 +00:00
|
|
|
import 'package:flutter_app/cwtch/gomobile.dart';
|
2021-01-06 23:09:58 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-01-21 20:37:35 +00:00
|
|
|
import 'package:flutter_app/views/triplecolview.dart';
|
2021-01-07 19:38:06 +00:00
|
|
|
import 'package:provider/provider.dart';
|
2021-01-12 06:21:18 +00:00
|
|
|
import 'cwtch/cwtch.dart';
|
2021-01-07 19:38:06 +00:00
|
|
|
import 'model.dart';
|
|
|
|
import 'views/profilemgrview.dart';
|
2021-01-13 23:17:02 +00:00
|
|
|
import 'views/splashView.dart';
|
2021-01-10 07:22:31 +00:00
|
|
|
import 'dart:io' show Platform;
|
2021-01-21 20:37:35 +00:00
|
|
|
import 'opaque.dart';
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
void main() => runApp(Flwtch());
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
class Flwtch extends StatefulWidget {
|
|
|
|
final Key flwtch = GlobalKey();
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
@override
|
|
|
|
FlwtchState createState() => FlwtchState();
|
2021-01-06 23:09:58 +00:00
|
|
|
}
|
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
class FlwtchState extends State<Flwtch> {
|
|
|
|
final TextStyle biggerFont = const TextStyle(fontSize: 18);
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-22 07:56:30 +00:00
|
|
|
// mergenotes: dan's
|
2021-01-12 06:21:18 +00:00
|
|
|
Cwtch cwtch;
|
2021-01-13 23:17:02 +00:00
|
|
|
bool cwtchInit = false;
|
2021-01-22 07:56:30 +00:00
|
|
|
|
|
|
|
// mergenotes: ui stuff
|
2021-01-21 20:37:35 +00:00
|
|
|
ProfileModel selectedProfile;
|
|
|
|
String selectedConversation = "";
|
2021-01-22 07:56:30 +00:00
|
|
|
var columns = [1];// default or 'single column' mode
|
2021-01-21 20:37:35 +00:00
|
|
|
//var columns = [1, 1, 2];
|
2021-01-22 07:56:30 +00:00
|
|
|
|
2021-01-07 19:38:06 +00:00
|
|
|
AppModel appStatus;
|
2021-01-13 23:17:02 +00:00
|
|
|
HashMap<String, ProfileModel> profiles;
|
2021-01-13 05:47:20 +00:00
|
|
|
|
2021-01-10 07:22:31 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
initState() {
|
|
|
|
super.initState();
|
2021-01-13 23:17:02 +00:00
|
|
|
cwtchInit = false;
|
|
|
|
profiles = new HashMap<String, ProfileModel>();
|
|
|
|
|
|
|
|
print("FlwtchState.initState()");
|
2021-01-10 07:22:31 +00:00
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
2021-01-13 05:47:20 +00:00
|
|
|
cwtch = CwtchGomobile();
|
|
|
|
} else {
|
|
|
|
cwtch = CwtchFfi();
|
2021-01-10 07:22:31 +00:00
|
|
|
}
|
2021-01-13 23:17:02 +00:00
|
|
|
cwtch.Start().then((val) {
|
|
|
|
setState(() {
|
|
|
|
cwtchInit = true;
|
|
|
|
loadProfiles();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
appStatus = AppModel(cwtch: cwtch);
|
|
|
|
// Timing issue? Start may not have inited cwtch yet when we ask for getProfiles...
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadProfiles() {
|
2021-01-22 07:56:30 +00:00
|
|
|
cwtch.GetProfiles().then((profilesJson) {
|
2021-01-13 23:17:02 +00:00
|
|
|
setState(() {
|
2021-01-22 07:56:30 +00:00
|
|
|
jsonDecode(profilesJson).forEach((profile) {
|
2021-01-13 23:17:02 +00:00
|
|
|
ProfileModel profile1 = new ProfileModel();
|
2021-01-22 07:56:30 +00:00
|
|
|
profile1.onion = profile['onion'];
|
|
|
|
profile1.nickname = profile['name'];
|
2021-01-13 23:17:02 +00:00
|
|
|
profile1.creationDate = "4 jan 2020";
|
|
|
|
profile1.contacts = new HashMap<String, ContactModel>();
|
2021-01-22 07:56:30 +00:00
|
|
|
profile1.imagePath = profile['imagePath'];
|
2021-01-13 23:17:02 +00:00
|
|
|
|
|
|
|
profiles.putIfAbsent(profile1.onion, () => profile1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2021-01-10 07:22:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-06 23:09:58 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-01-22 07:56:30 +00:00
|
|
|
appStatus = AppModel(cwtch: cwtch);
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-21 20:37:35 +00:00
|
|
|
final newTextTheme = Theme.of(context).textTheme.apply(
|
|
|
|
bodyColor: Opaque.current().mainTextColor(),
|
|
|
|
displayColor: Opaque.current().mainTextColor(),
|
|
|
|
);
|
2021-01-06 23:09:58 +00:00
|
|
|
|
2021-01-13 23:17:02 +00:00
|
|
|
print("FlwtchState.build() cwtchInit: $cwtchInit");
|
2021-01-07 19:38:06 +00:00
|
|
|
return Provider<FlwtchState>(
|
|
|
|
create: (_) => this,
|
|
|
|
child: MaterialApp(
|
2021-01-21 20:37:35 +00:00
|
|
|
title: 'Cwtch',
|
2021-01-07 19:38:06 +00:00
|
|
|
theme: ThemeData(
|
|
|
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
2021-01-21 20:37:35 +00:00
|
|
|
primarySwatch: Colors.red,
|
|
|
|
primaryColor: Opaque.current().backgroundMainColor(),
|
|
|
|
canvasColor: Opaque.current().backgroundPaneColor(),
|
|
|
|
accentColor: Opaque.current().defaultButtonColor(),
|
|
|
|
buttonColor: Opaque.current().defaultButtonColor(),
|
|
|
|
textTheme: newTextTheme,
|
2021-01-06 23:09:58 +00:00
|
|
|
),
|
2021-01-22 07:56:30 +00:00
|
|
|
// from dan: home: cwtchInit == true ? ProfileMgrView(cwtch) : SplashView(),
|
|
|
|
// from erinn: home: columns.length == 3 ? TripleColumnView() : ProfileMgrView(),
|
|
|
|
home: cwtchInit == true ? (columns.length == 3 ? TripleColumnView() : ProfileMgrView()) : SplashView(),
|
2021-01-07 19:38:06 +00:00
|
|
|
));
|
2021-01-06 23:09:58 +00:00
|
|
|
}
|
2021-01-07 19:38:06 +00:00
|
|
|
}
|