flutter_app/lib/main.dart

136 lines
4.0 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-27 20:18:28 +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;
2021-01-27 20:18:28 +00:00
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);
});
});
});
}
2021-01-27 20:18:28 +00:00
ChangeNotifierProvider<OpaqueTheme> getOpaqueProvider() {
return ChangeNotifierProvider(create: (context) => OpaqueTheme(Opaque.dark));
}
Provider<FlwtchState> getFlwtchStateProvider() {
return Provider<FlwtchState>(
create: (_) => this,
);
}
@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(
2021-01-27 20:18:28 +00:00
bodyColor: Opaque.current().mainTextColor(),
displayColor: Opaque.current().mainTextColor(),
);
print("FlwtchState.build() cwtchInit: $cwtchInit");
2021-01-27 20:18:28 +00:00
return MultiProvider(
providers: [getFlwtchStateProvider(), getOpaqueProvider()],
2021-01-28 23:25:30 +00:00
builder: (context, widget) {
return MaterialApp(
2021-01-27 20:18:28 +00:00
title: 'Cwtch',
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
primarySwatch: Colors.red,
primaryColor: Provider.of<OpaqueTheme>(context)
.current()
.backgroundMainColor(),
canvasColor: Provider.of<OpaqueTheme>(context)
.current()
.backgroundPaneColor(),
accentColor: Provider.of<OpaqueTheme>(context)
.current()
.defaultButtonColor(),
buttonColor: Provider.of<OpaqueTheme>(context)
.current()
.defaultButtonColor(),
textTheme: newTextTheme,
),
// 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-27 20:18:28 +00:00
}