flutter_app/lib/main.dart

103 lines
3.3 KiB
Dart
Raw Normal View History

2021-03-16 19:54:48 +00:00
import 'package:flutter/foundation.dart';
import 'package:flutter_app/cwtch/ffi.dart';
import 'package:flutter_app/cwtch/gomobile.dart';
import 'package:flutter/material.dart';
2021-03-24 23:35:24 +00:00
import 'package:flutter_app/errorHandler.dart';
import 'package:flutter_app/settings.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 'cwtch/cwtchNotifier.dart';
2021-03-16 19:54:48 +00:00
import 'licenses.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';
2021-02-23 02:55:10 +00:00
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2021-02-25 23:33:15 +00:00
2021-03-16 21:04:14 +00:00
var globalSettings = Settings(Locale("en", ''), Opaque.dark);
2021-03-24 23:35:24 +00:00
var globalErrorHandler = ErrorHandler();
2021-03-10 17:40:14 +00:00
2021-03-16 19:54:48 +00:00
void main() {
LicenseRegistry.addLicense(() => licenses());
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();
2021-03-24 23:35:24 +00:00
var cwtchNotifier = new CwtchNotifier(profs, globalSettings, globalErrorHandler);
if (Platform.isAndroid) {
cwtch = CwtchGomobile(cwtchNotifier);
} else {
cwtch = CwtchFfi(cwtchNotifier);
}
cwtch.Start().then((val) {
setState(() {
cwtchInit = true;
});
});
appStatus = AppModel(cwtch: cwtch);
2021-01-27 20:18:28 +00:00
}
2021-03-24 23:35:24 +00:00
ChangeNotifierProvider<ErrorHandler> getErrorHandlerProvider() => ChangeNotifierProvider.value(value: globalErrorHandler);
2021-03-17 22:54:41 +00:00
ChangeNotifierProvider<Settings> getSettingsProvider() => ChangeNotifierProvider.value(value: globalSettings);
2021-03-16 23:33:03 +00:00
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-03-23 22:42:10 +00:00
//appStatus = AppModel(cwtch: cwtch);
2021-01-27 20:18:28 +00:00
return MultiProvider(
2021-03-24 23:35:24 +00:00
providers: [getFlwtchStateProvider(), getProfileListProvider(), getSettingsProvider(), getErrorHandlerProvider()],
builder: (context, widget) {
Provider.of<Settings>(context).initPackageInfo();
2021-03-10 17:40:14 +00:00
return Consumer<Settings>(
builder: (context, opaque, child) => MaterialApp(
locale: Provider.of<Settings>(context).locale,
2021-02-23 02:55:10 +00:00
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
title: 'Cwtch',
theme: mkThemeData(opaque),
// from dan: home: cwtchInit == true ? ProfileMgrView(cwtch) : SplashView(),
// from erinn: home: columns.length == 3 ? TripleColumnView() : ProfileMgrView(),
2021-03-16 23:33:03 +00:00
home: cwtchInit == true ? (columns.length == 3 ? TripleColumnView() : ProfileMgrView()) : SplashView(),
),
);
},
2021-01-27 20:18:28 +00:00
);
}
2021-03-23 22:42:10 +00:00
@override
void dispose() {
cwtch.dispose();
super.dispose();
}
2021-01-27 20:18:28 +00:00
}