Skip to content

Instantly share code, notes, and snippets.

@AlexV525
Created July 6, 2020 07:53
Show Gist options
  • Save AlexV525/848201c1a1d4bd8f34edd1c7feb71eae to your computer and use it in GitHub Desktop.
Save AlexV525/848201c1a1d4bd8f34edd1c7feb71eae to your computer and use it in GitHub Desktop.
Two steps widget loader
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool isFirstStepFinished = false;
bool isSecondStepFinished = false;
int _counter = 0;
@override
void initState() {
super.initState();
loadFuturesStepByStep();
}
Future<void> loadFuturesStepByStep() async {
await Future<void>.delayed(Duration(seconds: 2), () {});
isFirstStepFinished = true;
if (mounted) setState(() {});
await Future<void>.delayed(Duration(seconds: 2), () {});
isSecondStepFinished = true;
if (mounted) setState(() {});
}
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: AnimatedSwitcher(
duration: kTabScrollDuration,
child: isFirstStepFinished
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
AnimatedSwitcher(
duration: kTabScrollDuration,
child: isSecondStepFinished
? Text(
'You have pushed the button this many times:',
)
: Text('Not finished yet, wait a sec...'),
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
)
: CircularProgressIndicator(),
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment