flutter_multitenancy 0.0.1 flutter_multitenancy: ^0.0.1 copied to clipboard
A multitenancy solution for flutter projects.
import 'package:flutter/material.dart';
import 'configs.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// The entire configs.dart fire will be overriden be the tenant one
title: Configs.APP_NAME,
theme: ThemeData(
primaryColor: HexColor(Configs.PRIMARY_COLOR),
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: Configs.APP_NAME + ' Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// The icon will change within each tenant
Container(
height: 100,
child: Image.asset("assets/images/icon.png"),
),
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
backgroundColor: Theme.of(context).primaryColor,
child: Icon(
Icons.add,
),
),
);
}
}
class HexColor extends Color {
static int _getColorFromHex(String hexColor) {
hexColor = hexColor.toUpperCase().replaceAll("#", "");
if (hexColor.length == 6) {
hexColor = "FF" + hexColor;
}
return int.parse(hexColor, radix: 16);
}
HexColor(final String hexColor) : super(_getColorFromHex(hexColor));
}