flutter_app/lib/main.dart

146 lines
5.6 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';
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-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-16 21:04:14 +00:00
var cwtchNotifier = new CwtchNotifier(profs, globalSettings);
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-10 17:40:14 +00:00
ChangeNotifierProvider<Settings> getSettingsProvider() =>
2021-03-16 21:04:14 +00:00
ChangeNotifierProvider(create: (context) => globalSettings);
2021-03-10 17:40:14 +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-01-22 07:56:30 +00:00
appStatus = AppModel(cwtch: cwtch);
2021-01-27 20:18:28 +00:00
return MultiProvider(
2021-03-10 17:40:14 +00:00
providers: [
getFlwtchStateProvider(),
getProfileListProvider(),
getSettingsProvider()
],
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: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
primarySwatch: Colors.red,
primaryColor: opaque.current().backgroundMainColor(),
canvasColor: opaque.current().backgroundPaneColor(),
accentColor: opaque.current().defaultButtonColor(),
buttonColor: opaque.current().defaultButtonColor(),
backgroundColor: opaque.current().backgroundMainColor(),
2021-03-10 17:40:14 +00:00
iconTheme: IconThemeData(
color: opaque.current().mainTextColor(),
),
cardColor: opaque.current().backgroundMainColor(),
2021-03-10 17:40:14 +00:00
textButtonTheme: TextButtonThemeData(
style: ButtonStyle(
2021-03-10 17:40:14 +00:00
backgroundColor: MaterialStateProperty.all(
opaque.current().defaultButtonColor()),
foregroundColor: MaterialStateProperty.all(
opaque.current().defaultButtonTextColor()),
overlayColor: MaterialStateProperty.all(
opaque.current().defaultButtonActiveColor()),
padding: MaterialStateProperty.all(EdgeInsets.all(20))),
),
2021-03-10 17:40:14 +00:00
dialogTheme: DialogTheme(
backgroundColor: opaque.current().backgroundPaneColor(),
titleTextStyle:
TextStyle(color: opaque.current().mainTextColor()),
contentTextStyle:
TextStyle(color: opaque.current().mainTextColor())),
textTheme: TextTheme(
2021-03-10 17:40:14 +00:00
headline1: TextStyle(color: opaque.current().mainTextColor()),
headline2: TextStyle(color: opaque.current().mainTextColor()),
headline3: TextStyle(color: opaque.current().mainTextColor()),
headline4: TextStyle(color: opaque.current().mainTextColor()),
headline5: TextStyle(color: opaque.current().mainTextColor()),
headline6: TextStyle(color: opaque.current().mainTextColor()),
bodyText1: TextStyle(color: opaque.current().mainTextColor()),
bodyText2: TextStyle(color: opaque.current().mainTextColor()),
subtitle1: TextStyle(color: opaque.current().mainTextColor()),
subtitle2: TextStyle(color: opaque.current().mainTextColor()),
caption: TextStyle(color: opaque.current().mainTextColor()),
button: TextStyle(color: opaque.current().mainTextColor()),
overline: TextStyle(color: opaque.current().mainTextColor())),
),
// from dan: home: cwtchInit == true ? ProfileMgrView(cwtch) : SplashView(),
// from erinn: home: columns.length == 3 ? TripleColumnView() : ProfileMgrView(),
2021-03-10 17:40:14 +00:00
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
}