Skip to content

Instantly share code, notes, and snippets.

@SemonCat
Last active April 26, 2018 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SemonCat/ce1f248356e37721fa42457c54d0720d to your computer and use it in GitHub Desktop.
Save SemonCat/ce1f248356e37721fa42457c54d0720d to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter_classs1/common_item.dart';
//Alice--入口點, 寫法相當於
//void main() {
// runApp(new MyApp()); //只有一行的話,建議簡化
//}
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
//Alice--MaterialApp是整個App最大的外層,包含很多屬性
return new MaterialApp(
home: new Class1Demo(),
);
}
}
class Class1Demo extends StatefulWidget {
bool startup = true;
@override
State<Class1Demo> createState() {
return new _Class1Demo();
}
}
abstract class ListItem {}
// A ListItem that contains data to display a heading
class HeadingItem implements ListItem {
final String heading;
HeadingItem(this.heading);
}
// A ListItem that contains data to display a message
class AppItem implements ListItem {
final String title;
final IconData titleIcon;
bool switchStatus = false;
AppItem(this.title, this.titleIcon);
}
final items = <ListItem>[
new HeadingItem("Selected Apps"),
new AppItem('Line', Icons.power_settings_new),
new AppItem('WeChat', Icons.add ),
new AppItem('Facebook', Icons.power_settings_new),
new HeadingItem("Recommand Apps"),
new AppItem('WhatApp', Icons.power_settings_new),
new AppItem('IG', Icons.power_settings_new),
new AppItem('SnapChat', Icons.power_settings_new),
];
class _Class1Demo extends State<Class1Demo> {
//?
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: const Text("Demo"),
backgroundColor: const Color(0xFFF00695C),
),
body:
new ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];
if (item is HeadingItem) {
return new ListTile(
title: new Text(
item.heading,
style: Theme.of(context).textTheme.headline,
),
);
} else if (item is AppItem) {
return new CommonItem(
title: item.title,
titleIcon: item.titleIcon,
isShowSwitch: item.switchStatus,
onTap: () {
setState(() {
item.switchStatus = !item.switchStatus;
});
},
);
}
}
)
// new Column(
// children: <Widget>[
// new SetAppTypeTitle(appTitle: "Selected Apps"),
// new CommonItem(
// title: "WeChat",
// titleIcon: Icons.power_settings_new,
// isShowSwitch: widget.startup,
// onTap: () {
// setState(() {
// widget.startup = !widget.startup;
// print("Alice_${widget.startup}");
// });
// },
// ),
// new Divider(height: 1.0, color: Colors.red),
// //Alice--橫線
// new CommonItem(
// title: "Line",
// titleIcon: Icons.message,
// isShowSwitch: true
// ),
// new SetAppTypeTitle(appTitle: "Recommand Apps"),
// new CommonItem(
// title: "Rate Us",
// titleIcon: Icons.star_border,
// isShowSwitch: true
// ),
// new CommonItem(
// title: "Messager",
// titleIcon: Icons.power_settings_new,
// isShowSwitch: true
// ),
// // new SetAppTypeTitle(appTitle: "Other Apps"),
// ],
// ));
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment