Commit e8236e54 authored by laishanqi's avatar laishanqi

学习demo

parent 2ee25249
......@@ -7,7 +7,7 @@
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="netrain_flutter_app"
android:label="NetRain互联网医院"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
......@@ -29,6 +29,10 @@
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<!-- 需要启动页 -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true"/>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" />
<item android:drawable="@android:color/holo_blue_light" />
<!-- You can insert your own image assets here -->
<!-- <item>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
android:src="@mipmap/ic_launcher" />
</item>
</layer-list>
/// 构造方法学习
class Cat {
String name;
String _color;
// 构造方法
Cat(this.name);
// 命名构造方法
Cat.copy(this.name);
@override
String toString() {
return name;
}
}
class BigCat extends Cat{
String age;
// 冒号后面的是初始化列表
BigCat(String name,String age) : age = age + "岁", super(name);
// 命名工厂构造方法
factory BigCat.big(String name,String age){
name = "我叫$name";
return BigCat(name, age);
}
@override
String toString() {
return "$name $age";
}
}
class Logger{
static Logger _cache;
factory Logger(){
if(_cache == null){
_cache = Logger._internal();
}
return _cache;
}
Logger._internal();
void log(String msg){
print("sinki: $msg");
}
}
class Dog{
String name;
String age;
void play(){
List list = [];
list[0]=1;
list[1]=0;
list[2]="";
list[3]=null;
// 空判断
if([0,"",null].contains(list[2])){
mLog("list[2] is empty");
}
Cat redCat = Cat.copy("红猫");
Cat blueCat = BigCat("蓝猫","123");
Cat cat ;
Logger().log(redCat.toString());
Logger().log(blueCat.toString());
Logger().log(cat?.toString()??"空对象");
mLog(cat?.name);
}
}
class Zom extends Cat with Dog{
Zom(String name) : super(name);
}
void mLog(String msg){
Logger().log(msg);
}
\ No newline at end of file
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'file:///E:/studioProject/netrain_flutter_app/netrain_flutter_app/lib/laishanqi/Cat.dart';
import 'layout_page.dart';
/// 有状态组件
class FulGroupPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _StatefulGroupState();
}
class _StatefulGroupState extends State<FulGroupPage> {
int _currentIndex = 0;
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Stateless学习',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text("Stateful基础组件"),
leading: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Icon(Icons.arrow_back),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Logger().log("点我了");
},
child: Text('click'),
),
bottomNavigationBar: BottomNavigationBar(
currentIndex: _currentIndex,
onTap: (index) {
setState(() {
_currentIndex = index;
});
},
items: [
BottomNavigationBarItem(
icon: Icon(
Icons.home,
color: Colors.grey,
),
activeIcon: Icon(
Icons.home,
color: Colors.blue,
),
title: Text("首页")),
BottomNavigationBarItem(
icon: Icon(
Icons.accessibility,
color: Colors.grey,
),
activeIcon: Icon(
Icons.accessibility,
color: Colors.blue,
),
title: Text("我的")),
],
),
body: _currentIndex == 0
? Container(
decoration: BoxDecoration(color: Colors.white),
alignment: Alignment.center,
child: Column(
children: <Widget>[
Image.network(
"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1600755280305&di=a7eeab2e720aac7cadfbd27b670dbdb1&imgtype=0&src=http%3A%2F%2Fpix2.tvzhe.com%2Fthumb%2Fstar%2F60%2F87%2F260x346.jpg",
width: 100,
height: 100,
),
TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(5, 0, 0, 0),
hintText: "请输入",
hintStyle: TextStyle(fontSize: 12)),
),
Container(
height: 100,
margin: EdgeInsets.only(top: 10),
decoration: BoxDecoration(color: Colors.lightBlue),
child: PageView(
children: <Widget>[
_item('page1', Colors.lightBlue),
_item('page2', Colors.red),
_item('page3', Colors.green)
],
),
),
],
),
)
: RefreshIndicator(
child: ListView(
children: <Widget>[
Text(text)
],
),
onRefresh: handleRefresh,
),
),
);
}
String text = "下拉刷新 ";
Future<String> handleRefresh() async {
text = "刷新中";
setState(() {
});
await Future.delayed(Duration(milliseconds: 2000));
text = "刷新完成";
setState(() {
});
return text;
}
_my() {
return LayoutPage();
}
_item(String title, MaterialColor color) {
return Container(
alignment: Alignment.center,
decoration: BoxDecoration(color: color),
child: Text(
title,
style: TextStyle(fontSize: 22, color: Colors.white),
),
);
}
}
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
/// 无状态组件
class LessGroupPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Stateless学习',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text("基础组件"),
leading: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Icon(Icons.arrow_back),
),
),
body: Container(
decoration: BoxDecoration(color: Colors.white),
alignment: Alignment.center,
child: Column(
children: <Widget>[
Text("text!!!!"),
Icon(
Icons.android,
size: 50,
color: Colors.blue,
),
CloseButton(),
BackButton(),
Chip(
avatar: Icon(Icons.people),
label: Text("啊啊啊啊啊"),
),
Divider(
height: 10,
indent: 10,
color: Colors.red,
),
Card(
color: Colors.blue,
elevation: 5,
margin: EdgeInsets.all(10),
child: Container(
padding: EdgeInsets.all(10),
child: Text(
"123123",
),
),
),
AlertDialog(
title: Text('标题'),
content: Text('这里是内容'),
)
],
),
),
),
);
}
}
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'file:///E:/studioProject/netrain_flutter_app/netrain_flutter_app/lib/laishanqi/Cat.dart';
import 'Stateful_page.dart';
class LayoutPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _LayoutGroupState();
}
class _LayoutGroupState extends State<LayoutPage> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'layout', // 打开最近任务的时候显示的标题
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
centerTitle: true,
leading: GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Icon(Icons.arrow_back),
),
title: Text("layout学习"),
),
body: Container(
decoration: BoxDecoration(color: Colors.white),
alignment: Alignment.center,
child: ListView(
children: [
Row(
children: [
ClipOval(
//圆形裁剪
child: SizedBox(
width: 100,
height: 100,
child: Image.network(
'http://pix2.tvzhe.com/thumb/star/60/87/260x346.jpg'),
),
),
Padding(
padding: EdgeInsets.all(10),
child: ClipRRect(
// 四个角度
borderRadius: BorderRadius.all(Radius.circular(20)),
child: Opacity(
opacity: 0.6, // 60%透明度
child: Image.network(
'http://pix2.tvzhe.com/thumb/star/60/87/260x346.jpg',
width: 100,
height: 100,
),
),
),
),
],
),
Container(
height: 100,
margin: EdgeInsets.all(10),
child: PhysicalModel(
color: Colors.transparent,
borderRadius: BorderRadius.circular(6),
clipBehavior: Clip.antiAlias,
child: PageView(
children: [
_item("1", Colors.blue),
_item("2", Colors.red),
_item("3", Colors.yellow),
],
),
),
),
FractionallySizedBox(
widthFactor: 1,
child: Container(
decoration: BoxDecoration(color: Colors.grey),
child: Text('宽度全屏'),
),
),
Stack(
children: [
ClipOval(
//圆形裁剪
child: SizedBox(
width: 100,
height: 100,
child: Image.network(
'http://pix2.tvzhe.com/thumb/star/60/87/260x346.jpg'),
),
),
Positioned(
right: 0,
top: 0,
child: Icon(
Icons.check_circle_outline,
color: Colors.red,
),
)
],
),
Wrap(
spacing: 8,
runSpacing: 6,
children: [
_chip("hello"),
_chip("中国"),
_chip("美国"),
_chip("越南"),
_chip("印度尼西亚"),
_chip("韩国"),
_chip("日本"),
_chip("英国"),
],
),
],
),
),
),
);
}
_item(String title, MaterialColor color) {
String content;
if (title == '1') {
content = "Earth";
} else if (title == '2') {
content = "China";
} else if (title == '3') {
content = "NetRain";
}
return Container(
alignment: Alignment.center,
decoration: BoxDecoration(color: color),
// child: Text(title,style: TextStyle(fontSize: 22,color: Colors.white),
child: Column(
children: [
Padding(
padding: EdgeInsets.all(10),
),
Text('Hello!!'),
Padding(
padding: EdgeInsets.all(10),
),
Text(
content,
style: TextStyle(color: Colors.white),
)
],
),
);
}
_chip(String label) {
return Chip(
label: Text(label),
avatar: CircleAvatar(
backgroundColor: Colors.yellow.shade900,
child: Text(
label.substring(0, 1),
style: TextStyle(fontSize: 15),
),
),
);
}
}
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'file:///E:/studioProject/netrain_flutter_app/netrain_flutter_app/lib/laishanqi/Cat.dart';
import 'layout_page.dart';
/// 有状态组件
class LoginPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _LoginState();
}
class _LoginState extends State<LoginPage> {
@override
Widget build(BuildContext context) {
var select = 1;
return MaterialApp(
title: '登陆页',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: SingleChildScrollView(
child: Container(
alignment: Alignment.topCenter,
padding: EdgeInsets.only(left: 16, right: 16),
child: Column(
children: [
Container(
margin: EdgeInsets.only(top: 108),
child: Image.asset("assets/images/logo_01.png"),
),
Container(
height: 40,
margin: EdgeInsets.only(top: 91),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
tab(1, select),
tab(2, select),
],
),
),
Container(
height: 47,
margin: EdgeInsets.only(left: 32, right: 32, top: 20),
child: TextField(
style: TextStyle(color: Colors.blue, fontSize: 16),
decoration: InputDecoration(
contentPadding: EdgeInsets.only(
left: 10, right: 10, top: 0, bottom: 0),
hintText: "请输入验证码",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(23),
borderSide: BorderSide(color: Color(0xFFf1f1f1)),
),
),
),
),
Container(
height: 47,
margin: EdgeInsets.only(left: 32, right: 32, top: 10),
child: TextField(
style: TextStyle(color: Colors.blue, fontSize: 16),
decoration: InputDecoration(
contentPadding: EdgeInsets.only(
left: 10, right: 10, top: 0, bottom: 0),
hintText: "请输入密码",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(23),
borderSide: BorderSide(color: Color(0xFFf1f1f1)),
),
),
),
),
Container(
height: 45,
margin: EdgeInsets.only(top: 30,left: 34,right: 34),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xff36D7FF), Color(0xff247DFF)]
),
borderRadius: BorderRadius.circular(22)
),
child: MaterialButton(
elevation: 0,
highlightElevation: 0,
minWidth: double.infinity,
color: Colors.transparent,
onPressed: () {},
child: Container(
child: Text(
"登陆",
style: TextStyle(color: Colors.white, fontSize: 18),
),
),
),
),
Container(
margin: EdgeInsets.only(top: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("快速注册",style: TextStyle(color: Colors.blue),),
Text(" | ",style: TextStyle(color: Colors.blue)),
Text("忘记密码",style: TextStyle(color: Colors.blue))
],
),
),
],
),
),
),
),
);
}
tab(int index, int selected) {
var style_01 = TextStyle(
fontWeight: FontWeight.bold, color: Color(0xff2893FF), fontSize: 16);
var style_02 = TextStyle(
fontWeight: FontWeight.bold, color: Color(0xff949494), fontSize: 16);
var currentStyle;
var text;
var image = Container(
margin: EdgeInsets.only(top: 5),
child: Image.asset("assets/images/ic_login_mode.png"),
);
if (index == 1) {
text = "验证码登陆";
currentStyle = style_01;
} else {
text = "账号密码登录";
currentStyle = style_02;
}
List<Widget> mChildren = [
Container(
alignment: Alignment.topCenter,
child: Text(
text,
style: currentStyle,
),
)
];
if (index == selected) {
mChildren.add(image);
}
return Column(children: mChildren);
}
}
import 'dart:io';
import 'package:flutter/material.dart';
import 'file:///E:/studioProject/netrain_flutter_app/netrain_flutter_app/lib/laishanqi/Cat.dart';
import 'file:///E:/studioProject/netrain_flutter_app/netrain_flutter_app/lib/laishanqi/layout_page.dart';
import 'package:image_picker/image_picker.dart';
class PhotoApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'PhotoApp Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home:MyHomePage()
// home: Scaffold(
// appBar: AppBar(
// title: Text("拍照"),
// ),
// ),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
File _image;
final picker = ImagePicker();
Future getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.gallery);
setState(() {
if (pickedFile != null) {
_image = File(pickedFile.path);
} else {
print('No image selected.');
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Image Picker Example'),
),
body: Center(
child: _image == null
? Text('No image selected.')
: Image.file(_image),
),
floatingActionButton: FloatingActionButton(
onPressed: getImage,
tooltip: 'Pick Image',
child: Icon(Icons.add_a_photo),
),
);
}
}
import 'package:flutter/material.dart';
import 'file:///E:/studioProject/netrain_flutter_app/netrain_flutter_app/lib/laishanqi/Cat.dart';
import 'file:///E:/studioProject/netrain_flutter_app/netrain_flutter_app/lib/laishanqi/layout_page.dart';
import 'laishanqi/Stateful_page.dart';
import 'laishanqi/Stateless_page.dart';
import 'laishanqi/loginPage.dart';
import 'laishanqi/photo.dart';
void main() {
runApp(MyApp());
......@@ -11,107 +18,71 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
// This makes the visual density adapt to the platform that you run
// the app on. For desktop platforms, the controls will be smaller and
// closer together (more dense) than on mobile platforms.
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
home: Scaffold(
appBar: AppBar(
title: Text("路由"),
),
body: RouterNavigator(title: 'Flutter Demo Home Page'),
),
routes: <String, WidgetBuilder>{
"less": (BuildContext context) => LessGroupPage(),
"ful": (BuildContext context) => FulGroupPage(),
"layout": (BuildContext context) => LayoutPage(),
"photo": (BuildContext context) => PhotoApp(),
});
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
class RouterNavigator extends StatefulWidget {
RouterNavigator({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
_RouterNavigatorState createState() => _RouterNavigatorState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
class _RouterNavigatorState extends State<RouterNavigator> {
bool byName = false;
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
return Container(
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
children: [
SwitchListTile(
title: Text('${byName ? '' : '不'}通过路由名跳转'),
value: byName,
onChanged: (value) {
setState(() {
byName = value;
});
}),
_item("less页面", LessGroupPage(), 'less'),
_item("ful页面", FulGroupPage(), 'ful'),
_item("layout页面", LayoutPage(), 'layout '),
_item("拍照页面", PhotoApp(), 'photo '),
_item("登陆", LoginPage(), 'login '),
],
),
);
}
_item(String title, page, String routeName) {
return Container(
child: RaisedButton(
onPressed: () {
if (byName) {
Navigator.pushNamed(context, routeName);
} else {
Navigator.push(
context, MaterialPageRoute(builder: (context) => page));
}
},
child: Text(title),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
......@@ -62,11 +62,46 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
name: flutter_plugin_android_lifecycle
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.11"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: transitive
description:
name: http
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.12.2"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.4"
image_picker:
dependency: "direct main"
description:
name: image_picker
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.6.7+11"
image_picker_platform_interface:
dependency: transitive
description:
name: image_picker_platform_interface
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.1.1"
matcher:
dependency: transitive
description:
......@@ -88,6 +123,20 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.7.0"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.2"
sky_engine:
dependency: transitive
description: flutter
......@@ -151,3 +200,4 @@ packages:
version: "2.0.8"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
flutter: ">=1.12.13 <2.0.0"
......@@ -28,6 +28,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
image_picker: ^0.6.7+11
dev_dependencies:
flutter_test:
......@@ -45,9 +46,9 @@ flutter:
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
assets:
- assets/images/logo_01.png
- assets/images/ic_login_mode.png
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment