Skip to content

Instantly share code, notes, and snippets.

@riskers
Last active September 21, 2019 23:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riskers/ee71c1754117981bf7358359b390ff4e to your computer and use it in GitHub Desktop.
Save riskers/ee71c1754117981bf7358359b390ff4e to your computer and use it in GitHub Desktop.
Flutter Widget Code
class Nav extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _TestState();
}
}
class _NavState extends State<Nav> {
int _count = 0;
int _selectIndex = 0;
final _options = [
Text('AA'),
Text('BB'),
Text('CC'),
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Test'),
),
body: Center(child: _options[_selectIndex]),
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(icon: Icon(Icons.chat), title: Text('A')),
BottomNavigationBarItem(icon: Icon(Icons.headset), title: Text('B')),
BottomNavigationBarItem(icon: Icon(Icons.settings), title: Text('C')),
],
currentIndex: _selectIndex,
fixedColor: Colors.cyan,
onTap: (int index) {
setState(() {
_selectIndex = index;
});
},
),
);
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Nav(),
);
}
}
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
title: 'Fultter',
home: Scaffold(
appBar: new AppBar(
title: new Text('Title'),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('aaa'),
Text('basdasdbb'),
Text('ccc')
],
)
)
)
);
}
}
import 'package:flutter/material.dart';
void main() => runApp(MyApp(
items: new List<String>.generate(1000, (i) => "Item $i")
));
class MyApp extends StatelessWidget {
final List<String> items;
MyApp({Key key, @required this.items}): super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter',
home: Scaffold(
appBar: new AppBar(title: new Text('Title')),
body: new ListView.builder(
itemCount: items.length,
itemBuilder: (context, index){
return new ListTile(
title: new Text('${items[index]}')
);
},
)
)
);
}
}
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter',
home: Scaffold(
appBar: new AppBar(title: new Text('Title')),
body: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3,
mainAxisSpacing: 4,
crossAxisSpacing: 4,
childAspectRatio: 0.7
),
children: <Widget>[
new Image.network('https://images.unsplash.com/photo-1542841791-c3cc44abdbbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80'),
new Image.network('https://images.unsplash.com/photo-1542841366-ddfe55c504a3?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60'),
new Image.network('https://images.unsplash.com/photo-1510520434124-5bc7e642b61d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60'),
new Image.network('https://images.unsplash.com/photo-1502898295-455afaf0f015?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60'),
new Image.network('https://images.unsplash.com/photo-1509503643053-8fc818177382?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'),
new Image.network('https://images.unsplash.com/photo-1433954558247-ba7696b9af19?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60'),
new Image.network('https://images.unsplash.com/photo-1512477815698-9ba49ad36d22?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60'),
new Image.network('https://images.unsplash.com/photo-1440589473619-3cde28941638?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60'),
new Image.network('https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60')
],
)
)
);
}
}
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
home: new MyHomePage(),
routes: <String, WidgetBuilder>{
'/settings': (BuildContext context) => new SettingsPage(),
},
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('TestProject'),
),
body: new Center(
child: new FlatButton(
child: const Text('Go to Settings'),
onPressed: () => Navigator.of(context).pushNamed('/settings')
)
)
);
}
}
class SettingsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('SettingsPage'),
),
body: new Center(
child: new Text('Settings')
)
);
}
}
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
title: 'Fultter',
home: Scaffold(
appBar: new AppBar(
title: new Text('Title'),
),
body: new Row(
children: <Widget>[
Expanded(
child: new RaisedButton(
onPressed: (){},
color: Colors.blue,
textColor: Colors.white,
child: new Text('1button'),
)
),
Expanded(
child: new RaisedButton(
onPressed: (){},
color: Colors.blue,
textColor: Colors.white,
child: new Text('2button'),
)
),
new RaisedButton(
onPressed: (){},
color: Colors.blue,
textColor: Colors.white,
child: new Text('bbbbutton'),
)
],
)
)
);
}
}
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// 抽组件
var stack = new Stack(
alignment: const FractionalOffset(0.5, 0.5),
children: <Widget>[
new CircleAvatar(
backgroundImage: new NetworkImage('https://images.unsplash.com/photo-1542841791-c3cc44abdbbb?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80'),
radius: 100,
),
new Container(
decoration: new BoxDecoration(
color: Colors.blue,
),
padding: EdgeInsets.all(5),
child: Text('riskers'),
)
],
);
return MaterialApp(
title: 'Fultter',
home: Scaffold(
appBar: new AppBar(
title: new Text('Title'),
),
body: Center(
child: stack
)
)
);
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter',
home: Scaffold(
appBar: new AppBar(title: new Text('Title')),
body: new ListView(
children: <Widget>[
new ListTile(
leading: new Icon(Icons.access_time),
title: new Text('abc'),
),
new ListTile(
leading: new Icon(Icons.access_alarms),
title: new Text('abc'),
),
new ListTile(
leading: new Icon(Icons.access_time),
title: new Text('abc'),
),
],
)
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment