Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/animation support #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# lazy_indexed_stack

懒加载IndexedStack
LazyIndexedStack works similar to the `IndexedStack` widget, but adds the ability to load widgets lazily and supports Fade animation when switching between widgets.

## Getting Started

Expand All @@ -16,13 +16,12 @@ import 'package:lazy_indexed_stack/lazy_indexed_stack.dart';
使用方法:

```
new LazyIndexedStack(
reuse: false,
index: index,
itemBuilder: (c,i){
return LoadingPage();
},
itemCount: 4,

)
LazyIndexedStack(
reuse: false,
index: selectedIndex,
itemBuilder: (context, index){
return LoadingPage();
},
itemCount: 4,
)
```
45 changes: 45 additions & 0 deletions example/lib/loading_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:flutter/material.dart';

class LoadingPage extends StatefulWidget {
@override
_LoadingPageState createState() => _LoadingPageState();
}

class _LoadingPageState extends State<LoadingPage> {
bool _loading = true;

@override
void initState() {
Future.delayed(Duration(seconds: 1)).then((e) {
setState(() {
_loading = false;
});
});
super.initState();
}

@override
Widget build(BuildContext context) {
return Center(
child: _loading
? Container(
child: Text(
"Loading....",
style: TextStyle(
fontSize: 30.0,
color: Colors.blue,
),
),
)
: Container(
child: Text(
"Loaded",
style: TextStyle(
fontSize: 30.0,
color: Colors.green,
),
),
),
);
}
}
94 changes: 29 additions & 65 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@ import 'package:flutter/material.dart';

import 'package:lazy_indexed_stack/lazy_indexed_stack.dart';

import 'loading_page.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
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,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
home: MyHomePage(title: 'LazyIndexedStack demo'),
);
}
}
Expand All @@ -36,78 +28,50 @@ class MyHomePage extends StatefulWidget {
_MyHomePageState createState() => _MyHomePageState();
}

class LoadingPage extends StatefulWidget {
@override
_LoadingPageState createState() => _LoadingPageState();
}

class _LoadingPageState extends State<LoadingPage> {
bool loading = true;

@override
void initState() {
Future.delayed(new Duration(seconds: 2)).then((e) {
setState(() {
loading = false;
});
});
super.initState();
}

@override
Widget build(BuildContext context) {
return loading
? new Container(
child: new Text("loading...."),
)
: Container(
child: new Text("load success"),
);
}
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
int index = 0;
int _selectedIndex = 0;

@override
Widget build(BuildContext context) {
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: new LazyIndexedStack(
body: LazyIndexedStack(
reuse: false,
index: index,
index: _selectedIndex,
itemBuilder: (c, i) {
return LoadingPage();
},
itemCount: 4,
),
bottomNavigationBar: new BottomNavigationBar(
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Colors.blueGrey,
selectedItemColor: Colors.amber,
unselectedItemColor: Colors.white70,
items: [
new BottomNavigationBarItem(
icon: new Icon(
Icons.add,
color: Colors.black38,
),
title: new Text("add")),
new BottomNavigationBarItem(
icon: new Icon(Icons.add, color: Colors.black38),
title: new Text("add")),
new BottomNavigationBarItem(
icon: new Icon(Icons.add, color: Colors.black38),
title: new Text("add")),
new BottomNavigationBarItem(
icon: new Icon(Icons.add, color: Colors.black38),
title: new Text("add")),
BottomNavigationBarItem(
icon: Icon(Icons.add, color: Colors.white),
title: Text("one"),
),
BottomNavigationBarItem(
icon: Icon(Icons.add, color: Colors.white),
title: Text("two"),
),
BottomNavigationBarItem(
icon: Icon(Icons.add, color: Colors.white),
title: Text("three"),
),
BottomNavigationBarItem(
icon: Icon(Icons.add, color: Colors.white),
title: Text("four"),
),
],
currentIndex: index,
currentIndex: _selectedIndex,
onTap: (i) {
setState(() {
index = i;
_selectedIndex = i;
});
},
),
Expand Down
Loading