Skip to content

Commit

Permalink
50更新
Browse files Browse the repository at this point in the history
  • Loading branch information
newlycn committed Apr 11, 2019
1 parent 33215ea commit 688124e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 42 deletions.
94 changes: 53 additions & 41 deletions lib/pages/cart_page.dart
Original file line number Diff line number Diff line change
@@ -1,56 +1,68 @@
import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import '../provide/counter.dart';
import 'package:shared_preferences/shared_preferences.dart';


class CartPage extends StatelessWidget {
class CartPage extends StatefulWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('购物车'),),
body: Container(
margin: EdgeInsets.only(top: 200),
child: Center(
child: Column(
children: <Widget>[
Number(),
MyButton()
],
),
)
),
);
}
_CartPageState createState() => _CartPageState();
}

class Number extends StatelessWidget {
class _CartPageState extends State<CartPage> {
List<String> testList =[];

@override
Widget build(BuildContext context) {
_show(); //每次进入前进行显示
return Container(
child: Center(
child: Provide<Counter>(
builder: (context,child,counter){
return Text(
"${counter.value}",
style: Theme.of(context).textTheme.display1
);
},
),
child: Column(
children: <Widget>[
Container(
height: 500,
child: ListView.builder(
itemCount: testList.length,
itemBuilder: (context,index){
return ListTile(
title: Text(testList[index]),
);
},
),
),
RaisedButton(
onPressed: (){_add();},
child: Text("增加"),
),
RaisedButton(
onPressed: (){_clear();},
child: Text("清空"),
),
],
),
);
}
}

class MyButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: RaisedButton(
onPressed: (){
Provide.value<Counter>(context).increment();
},
child: Text("递增"),
)
);
void _add() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String temp="技术胖是最胖的!";
testList.add(temp);
prefs.setStringList('testInfo', testList);
_show();
}

void _show() async{
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
if(prefs.getStringList('testInfo')!=null){
testList=prefs.getStringList('testInfo');
}
});
}

void _clear() async{
SharedPreferences prefs = await SharedPreferences.getInstance();
//prefs.clear(); //全部清空
prefs.remove('testInfo'); //删除key键
setState((){
testList=[];
});
}
}
2 changes: 1 addition & 1 deletion lib/pages/details_page/details_bottom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DetailsBottom extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
width: ScreenUtil().setWidth(750),
height: ScreenUtil().setHeight(80),
height: ScreenUtil().setHeight(90),
//padding: EdgeInsets.all(15),
child: Row(
children: <Widget>[
Expand Down
1 change: 1 addition & 0 deletions lib/pages/details_page/details_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DetailsWeb extends StatelessWidget {
} else {
return Container(
width: ScreenUtil().setWidth(750),
height: ScreenUtil().setHeight(600),
padding: EdgeInsets.all(10),
alignment: Alignment.center,
child:Text('暂时没有数据')
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies:
fluttertoast: ^3.0.1
fluro: ^1.4.0
flutter_html: ^0.9.6
shared_preferences: ^0.5.1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 688124e

Please sign in to comment.