platform_aware 0.1.0 copy "platform_aware: ^0.1.0" to clipboard
platform_aware: ^0.1.0 copied to clipboard

outdated

A new flutter package project.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:platform_aware/platform_aware_alert_dialog.dart';
import 'package:platform_aware/platform_aware_card.dart';
import 'package:platform_aware/platform_aware_checkbox.dart';
import 'package:platform_aware/platform_aware_flat_button.dart';
import 'package:platform_aware/platform_aware_icon.dart';
import 'package:platform_aware/platform_aware_icon_button.dart';
import 'package:platform_aware/platform_aware_list_tile.dart';
import 'package:platform_aware/platform_aware_picker.dart';
import 'package:platform_aware/platform_aware_raised_button.dart';
import 'package:platform_aware/platform_aware_scaffold.dart';

void main() => runApp(new DemoApp());

class DemoApp extends StatefulWidget {
  @override
  State createState() => new DemoAppState();
}

class DemoAppState extends State<DemoApp> {
  @override
  Widget build(BuildContext context) => new MaterialApp(
        title: 'Flutter Demo',
        initialRoute: '/',
        routes: {
          '/': (BuildContext context) => new MainMenu(),
          '/flatbutton': (BuildContext context) => new FlatButtonDemo(),
          '/raisedbutton': (BuildContext context) => new RaisedButtonDemo(),
          '/dialog': (BuildContext context) => new AlertDialogDemo(),
          '/card': (BuildContext context) => new CardDemo(),
          '/checkbox': (BuildContext context) => new CheckboxDemo(),
          '/picker': (BuildContext context) => new PickerDemo(),
          '/iconbutton': (BuildContext context) => new IconButtonDemo(),
        },
      );
}

class CardDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) => new PlatformAwareScaffold(
      title: new Text('Card'),
      body: new Column(
          children: new Iterable.generate(
              5,
              (_) => new Row(
                    children: <Widget>[
                      new Expanded(
                          child: new PlatformAwareCard(
                        title: new Text(
                          "Hello",
                          style: Theme.of(context).textTheme.headline,
                        ),
                        content: new Container(
                            padding: const EdgeInsets.all(4.0),
                            child: new Column(
                              children: <Widget>[
                                new Text("Place any content here"),
                                new Text("or here"),
                                new Text("or here"),
                              ],
                            )),
                      ))
                    ],
                    mainAxisAlignment: MainAxisAlignment.center,
                  )).toList()));
}

class CheckboxDemo extends StatefulWidget {
  @override
  State createState() => new CheckboxDemoState();
}

class CheckboxDemoState extends State<CheckboxDemo> {
  Map<int, bool> checkState = new Map.fromIterable(
      new Iterable<int>.generate(30),
      value: (key) => key % 2 > 0);

  @override
  Widget build(BuildContext context) => new PlatformAwareScaffold(
      title: new Text('Checkbox'),
      body: new ListView(
          children: checkState.entries
              .map((MapEntry<int, bool> entry) => new PlatformAwareListTile(
                    title: new Text('Checkbox ${entry.key}'),
                    onTap: () =>
                        setState(() => checkState[entry.key] = !entry.value),
                    trailing: new PlatformAwareCheckbox(
                      onChanged: (bool newChecked) =>
                          setState(() => checkState[entry.key] = newChecked),
                      value: entry.value,
                    ),
                  ))
              .toList()));
}

class PickerDemo extends StatefulWidget {
  @override
  State createState() => new PickerDemoState();
}

class PickerDemoState extends State<PickerDemo> {
  int selectedIndex = 0;
  final List<Color> items = <Color>[
    Colors.deepOrange,
    Colors.purple,
    Colors.blue,
    Colors.green,
    Colors.yellow,
    Colors.black,
    Colors.lightGreenAccent
  ];

  @override
  Widget build(BuildContext context) => new PlatformAwareScaffold(
      title: new Text('Picker'),
      body: new Center(
        child: new PlatformAwarePicker<Color>(
          initialItemIndex: selectedIndex,
          items: items,
          onChanged: (Color selectedColor) =>
              setState(() => selectedIndex = items.indexOf(selectedColor)),
          itemWidgetBuilder: (BuildContext context, Color item) => new Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                mainAxisSize: MainAxisSize.max,
                children: <Widget>[
                  new Container(
                    width: 15.0,
                    height: 15.0,
                    color: item,
                    margin: const EdgeInsets.only(right: 10.0),
                  ),
                  new Text("Color #${items.indexOf(item)}"),
                ],
              ),
        ),
      ));
}

class MainMenu extends StatelessWidget {
  @override
  Widget build(BuildContext context) => new PlatformAwareScaffold(
        title: new Text('platforn_aware demo'),
        body: new ListView(
          children: ListTile
              .divideTiles(
                  tiles: <String>[
                    'Flatbutton',
                    'Raisedbutton',
                    'Iconbutton',
                    'Dialog',
                    'Card',
                    'Checkbox',
                    'Picker'
                  ]
                      .map((String title) => new ListTile(
                            title: new Text(title),
                            onTap: () => Navigator
                                .of(context)
                                .pushNamed('/${title.toLowerCase()}'),
                          ))
                      .toList(),
                  color: Theme.of(context).dividerColor)
              .toList(growable: false),
        ),
        actions: <Widget>[
          new Container(
            child: new PlatformAwareIconButton(
                onPressed: () {},
                tooltip: 'Switch platform',
                icon: new PlatformAwareIcon(Icons.android)),
            padding: const EdgeInsets.only(right: 20.0),
          )
        ],
      );
}

class RaisedButtonDemoState extends State<RaisedButtonDemo> {
  int counter = 0;

  @override
  Widget build(BuildContext context) => new PlatformAwareScaffold(
      title: new Text('Button'),
      body: new Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          new Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              new Text(
                counter.toString(),
                style: Theme.of(context).textTheme.display1,
              ),
              new PlatformAwareRaisedButton(
                child: new Text("Click me"),
                onPressed: () => setState(() => ++counter),
              )
            ],
          )
        ],
      ));
}

class RaisedButtonDemo extends StatefulWidget {
  @override
  State createState() => new RaisedButtonDemoState();
}

class FlatButtonDemoState extends State<FlatButtonDemo> {
  int counter = 0;

  @override
  Widget build(BuildContext context) => new PlatformAwareScaffold(
      title: new Text('Button'),
      body: new Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          new Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              new Text(
                counter.toString(),
                style: Theme.of(context).textTheme.display1,
              ),
              new PlatformAwareFlatButton(
                child: new Text("Click me"),
                onPressed: () => setState(() => ++counter),
              )
            ],
          )
        ],
      ));
}

class FlatButtonDemo extends StatefulWidget {
  @override
  State createState() => new FlatButtonDemoState();
}

class IconButtonDemoState extends State<IconButtonDemo> {
  final List<Color> colors = <Color>[
    Colors.redAccent,
    Colors.blueAccent,
    Colors.deepOrange,
    Colors.green,
    Colors.purple
  ];
  int selectedColorIndex = 0;

  @override
  Widget build(BuildContext context) => new PlatformAwareScaffold(
        title: new Text('IconButton'),
        body: new Center(
          child: new PlatformAwareIconButton(
            iconSize: 100.0,
            icon: new Icon(
              Icons.settings,
              size: 100.0,
              color: colors.elementAt(selectedColorIndex),
            ),
            onPressed: () => setState(() =>
                selectedColorIndex = (selectedColorIndex + 1) % colors.length),
            tooltip: 'Settings',
          ),
        ),
      );
}

class IconButtonDemo extends StatefulWidget {
  @override
  State createState() => new IconButtonDemoState();
}

class AlertDialogDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) => new PlatformAwareScaffold(
      title: new Text('Dialog'),
      body: new Center(
        child: new PlatformAwareRaisedButton(
            onPressed: () => showDialog(
                context: context,
                builder: (BuildContext context) => new PlatformAwareAlertDialog(
                      title: new Text('Demo dialog'),
                      content: new Row(
                        children: <Widget>[
                          new Text('Some content'),
                          new PlatformAwareIcon(Icons.track_changes)
                        ],
                      ),
                      actions: <Widget>[
                        new PlatformAwareFlatButton(
                            onPressed: () => Navigator.of(context).pop(),
                            child: new Row(
                              children: <Widget>[
                                new Text("Done"),
                                new Icon(Icons.check)
                              ],
                            )),
                        new PlatformAwareFlatButton(
                            onPressed: () => Navigator.of(context).pop(),
                            child: new Row(
                              children: <Widget>[
                                new Text("Close"),
                                new Icon(Icons.close)
                              ],
                            ))
                      ],
                    )),
            child: new Text("Show dialog")),
      ));
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A new flutter package project.

Repository (GitLab)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on platform_aware