Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
Updating Format
Browse files Browse the repository at this point in the history
  • Loading branch information
rodydavis committed Sep 7, 2018
1 parent e3f7793 commit d439fae
Showing 1 changed file with 116 additions and 118 deletions.
234 changes: 116 additions & 118 deletions lib/flutter_cupertino_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ library flutter_cupertino_settings;
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

const CS_ITEM_HEIGHT = 50.0;
const CS_HEADER_COLOR = const Color(0xFFEEEEF3);
const CS_BORDER_COLOR = Colors.black12;
const CS_TEXT_COLOR = Colors.black;
const CS_HEADER_TEXT_COLOR = Colors.black54;
const CS_ITEM_PADDING = const EdgeInsets.only(left: 10.0, right: 10.0);
const CS_HEADER_FONT_SIZE = 14.0;
const CS_ITEM_NAME_SIZE = 16.0;
const CS_BUTTON_FONT_SIZE = CS_ITEM_NAME_SIZE;
const CS_ICON_PADDING = const EdgeInsets.only(right: 10.0);
const CS_DEFAULT_STYLE = const CSWidgetStyle();
const CS_CHECK_COLOR = Colors.blue;
const CS_CHECK_SIZE = 16.0;
const double CS_ITEM_HEIGHT = 50.0;
const Color CS_HEADER_COLOR = Color(0xFFEEEEF3);
const Color CS_BORDER_COLOR = Colors.black12;
const Color CS_TEXT_COLOR = Colors.black;
const Color CS_HEADER_TEXT_COLOR = Colors.black54;
const EdgeInsets CS_ITEM_PADDING = EdgeInsets.only(left: 10.0, right: 10.0);
const double CS_HEADER_FONT_SIZE = 14.0;
const double CS_ITEM_NAME_SIZE = 16.0;
const double CS_BUTTON_FONT_SIZE = CS_ITEM_NAME_SIZE;
const EdgeInsets CS_ICON_PADDING = EdgeInsets.only(right: 10.0);
const CSWidgetStyle CS_DEFAULT_STYLE = CSWidgetStyle();
const Color CS_CHECK_COLOR = Colors.blue;
const double CS_CHECK_SIZE = 16.0;

/// Event for [CSSelection]
typedef void SelectionCallback(int selected);
Expand All @@ -26,7 +26,7 @@ class CupertinoSettings extends StatelessWidget {

@override
Widget build(BuildContext context) {
return new ListView.builder(
return ListView.builder(
itemCount: items.length,
itemBuilder: (BuildContext context, int index) {
return items[index];
Expand All @@ -43,15 +43,15 @@ class CSHeader extends StatelessWidget {

@override
Widget build(BuildContext context) {
return new Container(
padding: new EdgeInsets.only(left: 10.0, top: 30.0, bottom: 5.0),
child: new Text(title.toUpperCase(), style: new TextStyle(color: CS_HEADER_TEXT_COLOR, fontSize: CS_HEADER_FONT_SIZE)),
decoration: new BoxDecoration(
return Container(
padding: const EdgeInsets.only(left: 10.0, top: 30.0, bottom: 5.0),
child: Text(title.toUpperCase(),
style: const TextStyle(
color: CS_HEADER_TEXT_COLOR, fontSize: CS_HEADER_FONT_SIZE)),
decoration: const BoxDecoration(
color: CS_HEADER_COLOR,
border: new Border(
bottom: new BorderSide(color: CS_BORDER_COLOR, width: 1.0)
)
),
border:
Border(bottom: BorderSide(color: CS_BORDER_COLOR, width: 1.0))),
);
}
}
Expand All @@ -66,40 +66,39 @@ class CSWidget extends StatelessWidget {
final double height;
final CSWidgetStyle style;

CSWidget(this.widget, {this.alignment, this.height = CS_ITEM_HEIGHT, this.style = CS_DEFAULT_STYLE});
CSWidget(this.widget,
{this.alignment,
this.height = CS_ITEM_HEIGHT,
this.style = CS_DEFAULT_STYLE});

@override
Widget build(BuildContext context) {

Widget child;

//style.icon
if (style.icon != null) {
child = new Row(children: <Widget>[
new Container(
child = Row(children: <Widget>[
Container(
child: style.icon,
padding: CS_ICON_PADDING,
),
new Expanded(child: widget)
Expanded(child: widget)
]);
} else {
child = widget;
}

return new Container(
return Container(
alignment: alignment,
height: height,
padding: CS_ITEM_PADDING,
decoration: new BoxDecoration(
decoration: const BoxDecoration(
color: Colors.white,
border: new Border(
bottom: new BorderSide(color: CS_BORDER_COLOR, width: 1.0)
),
border:
Border(bottom: BorderSide(color: CS_BORDER_COLOR, width: 1.0)),
),
child: child
);
child: child);
}

}

/// A title [name] in combination with any widget [contentWidget]
Expand All @@ -109,16 +108,19 @@ class CSControl extends CSWidget {
final String name;
final Widget contentWidget;

CSControl(this.name, this.contentWidget, {CSWidgetStyle style = CS_DEFAULT_STYLE}) : super(
new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
new Text(name, style: new TextStyle(fontSize: CS_ITEM_NAME_SIZE, color: CS_TEXT_COLOR)),
contentWidget
],
),
style: style
);
CSControl(this.name, this.contentWidget,
{CSWidgetStyle style = CS_DEFAULT_STYLE})
: super(
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(name,
style: const TextStyle(
fontSize: CS_ITEM_NAME_SIZE, color: CS_TEXT_COLOR)),
contentWidget
],
),
style: style);
}

/// A button-cell inside [CupertinoSettings]
Expand All @@ -144,45 +146,50 @@ class CSButton extends CSWidget {
final CSButtonType type;
final String text;
final VoidCallback pressed;
CSButton(this.type, this.text, this.pressed, {CSWidgetStyle style = CS_DEFAULT_STYLE}) : super(
new Flex(
direction: Axis.horizontal,
children: <Widget>[
new Expanded(
child: new CupertinoButton(
padding: EdgeInsets.zero,
child: new Container(
alignment: type.alignment,
child: new Text(text, style: new TextStyle(color: type.color, fontSize: CS_BUTTON_FONT_SIZE)),
),
onPressed: pressed,
CSButton(this.type, this.text, this.pressed,
{CSWidgetStyle style = CS_DEFAULT_STYLE})
: super(
Flex(
direction: Axis.horizontal,
children: <Widget>[
Expanded(
child: CupertinoButton(
padding: EdgeInsets.zero,
child: Container(
alignment: type.alignment,
child: Text(text,
style: TextStyle(
color: type.color,
fontSize: CS_BUTTON_FONT_SIZE)),
),
onPressed: pressed,
),
),
],
),
),
],
),
style: style
);
style: style);
}

/// Provides a button for navigation
class CSLink extends CSWidget {
final String text;
final VoidCallback pressed;
CSLink(this.text, this.pressed, {CSWidgetStyle style = CS_DEFAULT_STYLE}) : super (
new CupertinoButton(
padding: EdgeInsets.zero,
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
new Text(text, style: new TextStyle(fontSize: CS_ITEM_NAME_SIZE, color: CS_TEXT_COLOR)),
new Icon(Icons.keyboard_arrow_right, color: Colors.black26)
],
),
onPressed: pressed
),
style: style
);

CSLink(this.text, this.pressed, {CSWidgetStyle style = CS_DEFAULT_STYLE})
: super(
CupertinoButton(
padding: EdgeInsets.zero,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(text,
style: const TextStyle(
fontSize: CS_ITEM_NAME_SIZE, color: CS_TEXT_COLOR)),
const Icon(Icons.keyboard_arrow_right,
color: Colors.black26)
],
),
onPressed: pressed),
style: style);
}

/// A selection view
Expand All @@ -197,7 +204,6 @@ class CSLink extends CSWidget {
///
/// onSelected(1)
class CSSelection extends StatefulWidget {

final List<String> items;
final SelectionCallback onSelected;
final int currentSelection;
Expand All @@ -206,14 +212,12 @@ class CSSelection extends StatefulWidget {

@override
State<StatefulWidget> createState() {
return new CSSelectionState(items, currentSelection, onSelected);
return CSSelectionState(items, currentSelection, onSelected);
}

}

/// [State] for [CSSelection]
class CSSelectionState extends State<CSSelection> {

int currentSelection;
final SelectionCallback onSelected;
final List<String> items;
Expand All @@ -222,46 +226,37 @@ class CSSelectionState extends State<CSSelection> {

@override
Widget build(BuildContext context) {

List<Widget> widgets = new List<Widget>();
for(int i = 0; i < items.length; i++) {
widgets.add(createItem(items[i],i));
final List<Widget> widgets = <Widget>[];
for (int i = 0; i < items.length; i++) {
widgets.add(createItem(items[i], i));
}

return new Column(
children: widgets
);
return Column(children: widgets);
}

Widget createItem(String name, int index) {
return new CSWidget(
new CupertinoButton(
onPressed: (){
if (index != this.currentSelection) {
setState(() {
this.currentSelection = index;
});
onSelected(index);
}
},
pressedOpacity: 1.0,
child: new Row(
children: <Widget>[
new Expanded(
child: new Text(
name,
style: new TextStyle(fontSize: CS_ITEM_NAME_SIZE, color: CS_TEXT_COLOR))
),
new Icon(Icons.check,
color: (index == currentSelection ? CS_CHECK_COLOR : Colors.transparent),
size: CS_CHECK_SIZE
)
],
)
)
);
return CSWidget(new CupertinoButton(
onPressed: () {
if (index != currentSelection) {
setState(() => currentSelection = index);
onSelected(index);
}
},
pressedOpacity: 1.0,
child: Row(
children: <Widget>[
Expanded(
child: Text(name,
style: const TextStyle(
fontSize: CS_ITEM_NAME_SIZE, color: CS_TEXT_COLOR))),
Icon(Icons.check,
color: (index == currentSelection
? CS_CHECK_COLOR
: Colors.transparent),
size: CS_CHECK_SIZE)
],
)));
}

}

/// Defines style attributes that can be applied to every [CSWidget]
Expand All @@ -273,9 +268,12 @@ class CSWidgetStyle {
/// Defines different types for [CSButton]
/// Specifies color and alignment
class CSButtonType {
static const DESTRUCTIVE = const CSButtonType(Colors.red, AlignmentDirectional.center);
static const DEFAULT = const CSButtonType(Colors.blue, AlignmentDirectional.centerStart);
static const DEFAULT_CENTER = const CSButtonType(Colors.blue, AlignmentDirectional.center);
static const CSButtonType DESTRUCTIVE =
CSButtonType(Colors.red, AlignmentDirectional.center);
static const CSButtonType DEFAULT =
CSButtonType(Colors.blue, AlignmentDirectional.centerStart);
static const CSButtonType DEFAULT_CENTER =
CSButtonType(Colors.blue, AlignmentDirectional.center);

final Color color;
final AlignmentGeometry alignment;
Expand Down

0 comments on commit d439fae

Please sign in to comment.