flutter_app/lib/main.dart

111 lines
3.2 KiB
Dart
Raw Normal View History

import 'dart:collection';
import 'dart:convert';
import 'package:flutter_app/cwtch/ffi.dart';
import 'package:flutter_app/cwtch/gomobile.dart';
import 'package:flutter/material.dart';
2021-01-21 20:37:35 +00:00
import 'package:flutter_app/views/triplecolview.dart';
import 'package:provider/provider.dart';
import 'cwtch/cwtch.dart';
import 'model.dart';
import 'views/profilemgrview.dart';
import 'views/splashView.dart';
import 'dart:io' show Platform;
2021-01-21 20:37:35 +00:00
import 'opaque.dart';
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);
2021-01-22 07:56:30 +00:00
// mergenotes: dan's
Cwtch cwtch;
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
AppModel appStatus;
HashMap<String, ProfileModel> profiles;
@override
initState() {
super.initState();
cwtchInit = false;
profiles = new HashMap<String, ProfileModel>();
print("FlwtchState.initState()");
if (Platform.isAndroid) {
cwtch = CwtchGomobile();
} else {
cwtch = CwtchFfi();
}
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) {
setState(() {
2021-01-22 07:56:30 +00:00
jsonDecode(profilesJson).forEach((profile) {
ProfileModel profile1 = new ProfileModel();
2021-01-22 07:56:30 +00:00
profile1.onion = profile['onion'];
profile1.nickname = profile['name'];
profile1.creationDate = "4 jan 2020";
profile1.contacts = new HashMap<String, ContactModel>();
2021-01-22 07:56:30 +00:00
profile1.imagePath = profile['imagePath'];
profiles.putIfAbsent(profile1.onion, () => profile1);
});
});
});
}
@override
Widget build(BuildContext context) {
2021-01-22 07:56:30 +00:00
appStatus = AppModel(cwtch: cwtch);
2021-01-21 20:37:35 +00:00
final newTextTheme = Theme.of(context).textTheme.apply(
bodyColor: Opaque.current().mainTextColor(),
displayColor: Opaque.current().mainTextColor(),
);
print("FlwtchState.build() cwtchInit: $cwtchInit");
return Provider<FlwtchState>(
create: (_) => this,
child: MaterialApp(
2021-01-21 20:37:35 +00:00
title: 'Cwtch',
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-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(),
));
}
}