unify_api 1.2.10+13 unify_api: ^1.2.10+13 copied to clipboard
A Unify API Wrapper
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:unify_api/tool.dart';
import 'package:unify_api_example/ui/greatness_tracker.dart';
import 'package:unify_api_example/utils/index.dart';
import 'common/index.dart';
import 'ui/index.dart';
void main() {
_setTargetPlatformForDesktop();
runApp(MyApp());
}
void _setTargetPlatformForDesktop({TargetPlatform platform}) {
var targetPlatform = platform;
if (targetPlatform != null) {
targetPlatform = platform;
} else if (Platform.isIOS || Platform.isMacOS) {
targetPlatform = TargetPlatform.iOS;
} else if (Platform.isLinux || Platform.isWindows || Platform.isAndroid) {
targetPlatform = TargetPlatform.android;
} else {
targetPlatform = TargetPlatform.fuchsia;
}
if (targetPlatform != null) {
debugDefaultTargetPlatformOverride = targetPlatform;
}
}
class MyApp extends StatelessWidget {
const MyApp({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomeScreen(),
);
}
}
class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
UnifyClient _client;
final TextEditingController _username = TextEditingController();
final TextEditingController _password = TextEditingController();
final TextEditingController _domain =
TextEditingController(text: 'mobile.myunifycrm.com');
bool _loading = false;
String _error = '';
@override
Widget build(BuildContext context) {
if (_client == null || !_client.isAuthorized)
return Scaffold(
appBar: AppBar(title: Text('Login - Unify API')),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
ListTile(
title: TextField(
controller: _username,
decoration: InputDecoration(hintText: 'Username'),
),
),
ListTile(
title: TextField(
controller: _password,
// obscureText: true,
decoration: InputDecoration(hintText: 'Password'),
),
),
ListTile(
title: TextField(
controller: _domain,
decoration: InputDecoration(hintText: 'Domain'),
),
),
RaisedButton.icon(
icon: Icon(Icons.account_circle),
label: Text('Login'),
onPressed: () async {
setState(() {
_loading = true;
});
try {
_client = getUnifyClient(
unifyUsername: _username.text,
unifyPassword: _password.text,
domain: _domain.text.contains('mobile.')
? _domain.text
: 'api.${_domain.text}',
);
await _client.login();
} catch (e) {
_error = e.toString();
}
setState(() {
_loading = false;
});
},
),
// if (_loading)
// Row(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.center,
// children: <Widget>[
// Center(child: CircularProgressIndicator())
// ],
// ),
Text(_error),
],
),
),
);
return Scaffold(
appBar: AppBar(
title: const Text('Overview - Unify API'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.exit_to_app),
onPressed: () {
setState(() {
_client = null;
});
},
)
],
),
body: LayoutBuilder(
builder: (context, dimens) => GridView.count(
crossAxisCount: getCrossCount(dimens),
children: <Widget>[
GridItem(
iconData: Icons.account_circle,
name: 'Account',
details: AccountInfoExample(client: _client),
),
GridItem(
iconData: Icons.contacts,
name: 'Contacts',
details: ContactsExample(client: _client),
),
GridItem(
iconData: Icons.people,
name: 'Leads',
details: LeadsExample(client: _client),
),
GridItem(
iconData: Icons.people_outline,
name: 'Lead Tracker',
details: CoreLeadsExample(client: _client),
),
GridItem(
iconData: Icons.track_changes,
name: 'Greatness Tracker',
details: GreatnessTracker(client: _client,),
),
GridItem(
iconData: Icons.dashboard,
name: 'Dashboard',
details: DashboardAlertsExample(client: _client),
),
GridItem(
iconData: Icons.group,
name: 'Contact Groups',
details: ContactGroupsExample(client: _client),
),
GridItem(
iconData: Icons.group,
name: 'Lead Groups',
details: LeadGroupsExample(client: _client),
),
GridItem(
iconData: Icons.folder,
name: 'Loan Folders',
details: LoanFolderExample(client: _client),
),
GridItem(
iconData: Icons.video_library,
name: 'Unify Video',
details: VideoExample(client: _client),
),
GridItem(
iconData: Icons.info_outline,
name: 'Marketing',
details: MarketingExample(client: _client),
),
GridItem(
iconData: Icons.shopping_cart,
name: 'Cart',
details: CartExample(client: _client),
),
],
),
));
}
}