Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Improved example app. Extracted loading page to a separate file.
  • Loading branch information
vovahost committed Jun 17, 2020
commit 0d24e6b27d85f0bebea231702fa518e3f1c84dcc
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