Skip to content

Commit

Permalink
常用布局、组件、http请求
Browse files Browse the repository at this point in the history
  • Loading branch information
flute committed Jan 15, 2019
1 parent 510485f commit c164751
Show file tree
Hide file tree
Showing 27 changed files with 1,020 additions and 149 deletions.
Binary file added assets/icon/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon/9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
111 changes: 92 additions & 19 deletions lib/bottomTabs/colleague.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,102 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'dart:async';

class ColleagueTab extends StatefulWidget {
@override
ColleagueTabState createState() => ColleagueTabState();
}

class ColleagueTabState extends State<ColleagueTab> {
var _jsonData = '';
ScrollController _controller = new ScrollController();
bool isPerformingRequest = false; // 是否有请求正在进行
List<int> items = List.generate(10, (i) => i);

@override
void initState() {
super.initState();
_fetchData();
_controller.addListener((){
if(_controller.position.pixels == _controller.position.maxScrollExtent) {
print('下拉加载');
}
});
}

@override
void dispose() {
_controller.dispose();
super.dispose();
}

_fetchData() async {
var apiUrl = 'http://v.juhe.cn/toutiao/index?type=top&key=a27aecf7dbae5c7555900e57c8212c46';
var httpClient = new HttpClient();

var result;
try {
var request = await httpClient.getUrl(Uri.parse(apiUrl));
var response = await request.close();
if (response.statusCode == HttpStatus.OK) {
var jsonStr = await response.transform(utf8.decoder).join();
var data = json.decode(jsonStr);
result = jsonStr;
//print(data);
} else {
print('response statusCode not equal 200');
}
} catch (exception) {
print('fetch data error: $exception');
}

// If the widget was removed from the tree while the message was in flight,
// we want to discard the reply rather than calling setState to update our
// non-existent appearance.
if (!mounted) return;

if(result != '') {
setState(() {
_jsonData = result;
});
}

}

Future<Null> _onRefresh() {
Completer<Null> completer = new Completer<Null>();

new Timer(new Duration(seconds: 3), () {
print("timer complete");
completer.complete();
});

return completer.future;
}

class ColleagueTab extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return new Scaffold(
// backgroundColor: Colors.red,
body: new Container(
child: new Center(
child: new Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(
Icons.school,
size: 160.0,
color: Colors.black87,
),
new Text(
"大学",
style: new TextStyle(color: Colors.black87),
)
],
appBar: new AppBar(
title: new Text('Http请求'),
),
body: new RefreshIndicator(
onRefresh: _onRefresh,
child: new SingleChildScrollView(
controller: _controller,
child: new Container(
padding: EdgeInsets.all(10),
child: new Column(
children: <Widget>[
Text('下拉刷新'),
new Text(_jsonData)
],
),
),
),
),
)
);
}
}
98 changes: 83 additions & 15 deletions lib/bottomTabs/idea.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,97 @@
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class IdeaTab extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Scaffold(
// backgroundColor: Colors.red,
appBar: new AppBar(
title: new Text('想法'),
),
body: new Container(
child: new Center(
child: new Column(
// center the children
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Icon(
Icons.favorite,
size: 160.0,
color: Colors.black87,
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new Container(
height: 200,
child: new _Swiper(),
),
new Expanded(
child: new Center(
child: Container(
child: Text('想法'),
),
),
new Text(
"想法",
style: new TextStyle(color: Colors.black87),
)
],
),
),
],
),
),
floatingActionButton: new FloatingActionButton(
onPressed: (){
_showDialog(context);
},
child: Icon(Icons.edit),
//mini: true,
),
);
}

void _showDialog(BuildContext context) {
// flutter defined function
showDialog(
context: context,
builder: (BuildContext context) {
// return object of type Dialog
return AlertDialog(
title: Text('Rewind and remember'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('You will never be satisfied.'),
Text('You\’re like me. I’m never satisfied.'),
],
),
),
actions: <Widget>[
// usually buttons at the bottom of the dialog
new FlatButton(
child: new Text("Close"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}

class _Swiper extends StatefulWidget {
@override
_SwiperState createState() => _SwiperState();
}

var images = [
'https://pic3.zhimg.com/v2-5806d9e33e36fa772c8da56c931bb416_b.jpg',
'https://pic1.zhimg.com/50/v2-f355ca177e011626938b479f0e2e3e03_hd.jpg',
'https://pic2.zhimg.com/v2-d8e47ed961b93b875ad814104016bdfd_b.jpg'
];

class _SwiperState extends State<_Swiper> {
@override
Widget build(BuildContext context) {
return new Container(
child: new Swiper(
itemBuilder: (BuildContext context,int index){
return new Image.network(images[index], fit: BoxFit.cover,);
},
itemCount: 3,
pagination: new SwiperPagination(),
//control: new SwiperControl(),
),
);

}
}
Loading

0 comments on commit c164751

Please sign in to comment.