flutter_app/lib/main.dart

117 lines
3.8 KiB
Dart
Raw Normal View History

import 'dart:collection';
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);
Cwtch cwtch;
bool cwtchInit = false;
ProfileInfoState selectedProfile;
2021-01-21 20:37:35 +00:00
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];
AppModel appStatus;
ProfileListState profs;
@override
initState() {
super.initState();
cwtchInit = false;
profs = ProfileListState();
if (Platform.isAndroid) {
cwtch = CwtchGomobile(profs);
} else {
2021-02-06 00:32:35 +00:00
cwtch = CwtchFfi(profs);
}
cwtch.Start().then((val) {
setState(() {
cwtchInit = true;
});
});
appStatus = AppModel(cwtch: cwtch);
2021-02-06 00:32:35 +00:00
/* // Timing issue? Start may not have inited cwtch yet when we ask for getProfiles...
}
void loadProfiles() {
cwtch.GetProfiles().then((profilesJson) {
if (profilesJson != null) {
setState(() {
jsonDecode(profilesJson).forEach((profile) {
ProfileModel profile1 = new ProfileModel();
profile1.onion = profile['onion'];
profile1.nickname = profile['name'];
profile1.creationDate = "4 jan 2020";
profile1.contacts = new HashMap<String, ContactModel>();
profile1.imagePath = profile['imagePath'];
profiles.putIfAbsent(profile1.onion, () => profile1);
});
});
}
});
}
ChangeNotifierProvider<OpaqueTheme> getOpaqueProvider() {
return ChangeNotifierProvider(create: (context) => OpaqueTheme(Opaque.dark)); */
2021-01-27 20:18:28 +00:00
}
ChangeNotifierProvider<OpaqueTheme> getOpaqueProvider() => ChangeNotifierProvider(create: (context) => OpaqueTheme(Opaque.dark));
Provider<FlwtchState> getFlwtchStateProvider() => Provider<FlwtchState>(create: (_) => this);
ChangeNotifierProvider<ProfileListState> getProfileListProvider() => ChangeNotifierProvider(create: (context) => profs);
2021-01-27 20:18:28 +00:00
@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(),
);
2021-01-27 20:18:28 +00:00
return MultiProvider(
providers: [getFlwtchStateProvider(), getProfileListProvider(), getOpaqueProvider()],
builder: (context, widget) {
return Consumer<OpaqueTheme>(
builder: (context, opaque, child) => MaterialApp(
title: 'Cwtch',
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
primarySwatch: Colors.red,
primaryColor: opaque.current().backgroundMainColor(),
canvasColor: opaque.current().backgroundPaneColor(),
accentColor: opaque.current().defaultButtonColor(),
buttonColor: opaque.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
);
}
2021-01-27 20:18:28 +00:00
}