unify_api 1.2.7-beta.3 copy "unify_api: ^1.2.7-beta.3" to clipboard
unify_api: ^1.2.7-beta.3 copied to clipboard

unlistedoutdated

A Unify API Wrapper

example/lib/main.dart

import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:unify_api/tool.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.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),
              ),
            ],
          ),
        ));
  }
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A Unify API Wrapper

Homepage

License

unknown (license)

Dependencies

html, http, intl, meta

More

Packages that depend on unify_api