Finally - A Mobile App Basic Implementation
This commit is contained in:
105
web_native/lib/screens/HomeScreen.dart
Normal file
105
web_native/lib/screens/HomeScreen.dart
Normal file
@@ -0,0 +1,105 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
static const String PATH = '/Home';
|
||||
|
||||
HomeScreen({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_HomeScreenState createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
|
||||
// HomeBloc bloc;
|
||||
|
||||
void _init(){
|
||||
// if(null == bloc){
|
||||
// bloc = HomeBloc(AppProvider.getApplication(context));
|
||||
// }
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
// bloc.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_init();
|
||||
|
||||
return PlatformScaffold(
|
||||
body: _buildGridView(),
|
||||
bottomNavBar: _buildNavBar()
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNavBar() {
|
||||
return PlatformNavBar(
|
||||
currentIndex: 0,
|
||||
itemChanged: (index) => setState(
|
||||
() {
|
||||
// _selectedTabIndex = index;
|
||||
print(index);
|
||||
},
|
||||
),
|
||||
items: [
|
||||
BottomNavigationBarItem(
|
||||
label: "Gallery",
|
||||
icon: Icon(PlatformIcons(context).collections),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
label: "Me",
|
||||
icon: Icon(PlatformIcons(context).person),
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
label: "Settings",
|
||||
icon: Icon(PlatformIcons(context).settings),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGridView() {
|
||||
// return GridView.builder(
|
||||
// itemCount: 5,
|
||||
// gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
|
||||
// childAspectRatio: (1 / 1),
|
||||
// crossAxisCount: 2),
|
||||
// itemBuilder: (BuildContext context, int index) {
|
||||
// return _buildCard("https://i.imgur.com/CgSGqUz.jpeg");
|
||||
// }
|
||||
// );
|
||||
|
||||
|
||||
return new StaggeredGridView.countBuilder(
|
||||
crossAxisCount: 4,
|
||||
itemCount: 80,
|
||||
itemBuilder: (BuildContext context, int index) => _buildCard("https://i.imgur.com/CgSGqUz.jpeg"),
|
||||
// itemBuilder: (BuildContext context, int index) => new Container(
|
||||
// color: Colors.green,
|
||||
// child: new Center(
|
||||
// child: new CircleAvatar(
|
||||
// backgroundColor: Colors.white,
|
||||
// child: new Text('$index'),
|
||||
// ),
|
||||
// )),
|
||||
staggeredTileBuilder: (int index) =>
|
||||
// new StaggeredTile.count(2, index.isEven ? 2 : 1),
|
||||
new StaggeredTile.fit(2),
|
||||
mainAxisSpacing: 4.0,
|
||||
crossAxisSpacing: 4.0,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCard(charImageUrl) {
|
||||
return new Image.network(
|
||||
charImageUrl,
|
||||
fit: BoxFit.contain,
|
||||
);
|
||||
}
|
||||
}
|
||||
94
web_native/lib/screens/LoginScreen.dart
Normal file
94
web_native/lib/screens/LoginScreen.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:fluro/fluro.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
|
||||
import 'package:imagini/core/AppProvider.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
static const String PATH = '/Login';
|
||||
|
||||
LoginScreen({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_LoginScreenState createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
|
||||
// LoginBloc bloc;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
// bloc.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_init();
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 500),
|
||||
child: Container(
|
||||
margin: EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
height: 500,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
child: const FlutterLogo(),
|
||||
),
|
||||
width: 175,
|
||||
margin: EdgeInsets.fromLTRB(0, 0, 0, 50),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Server Address'
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Username / Email'
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
obscureText: true,
|
||||
enableSuggestions: false,
|
||||
autocorrect: false,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Password'
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: PlatformButton(
|
||||
onPressed: () {
|
||||
AppProvider.getRouter(context).navigateTo(context, "/Home", transition: TransitionType.fadeIn);
|
||||
},
|
||||
child: Text('Login')
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _init(){
|
||||
// if(null == bloc){
|
||||
// bloc = LoginBloc(AppProvider.getApplication(context));
|
||||
// }
|
||||
}
|
||||
}
|
||||
70
web_native/lib/screens/SplashScreen.dart
Normal file
70
web_native/lib/screens/SplashScreen.dart
Normal file
@@ -0,0 +1,70 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
import 'package:fluro/fluro.dart';
|
||||
|
||||
import 'package:imagini/models/api/response/LoginResponse.dart';
|
||||
import 'package:imagini/core/AppProvider.dart';
|
||||
import 'package:imagini/blocs/SplashBloc.dart';
|
||||
|
||||
class SplashScreen extends StatefulWidget {
|
||||
static const String PATH = '/';
|
||||
|
||||
SplashScreen({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SplashScreenState createState() => _SplashScreenState();
|
||||
}
|
||||
|
||||
class _SplashScreenState extends State<SplashScreen> {
|
||||
|
||||
SplashBloc bloc;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
bloc.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_init();
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: 500),
|
||||
child: Container(
|
||||
margin: EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
height: 270,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
child: const FlutterLogo(),
|
||||
),
|
||||
width: 175,
|
||||
margin: EdgeInsets.fromLTRB(0, 0, 0, 50),
|
||||
),
|
||||
PlatformCircularProgressIndicator()
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _init(){
|
||||
if(null == bloc){
|
||||
bloc = SplashBloc(AppProvider.getApplication(context));
|
||||
bloc.loginResult.listen((LoginResponse lr) {
|
||||
if (lr.error != null) {
|
||||
AppProvider.getRouter(context).navigateTo(context, "/Login", transition: TransitionType.fadeIn);
|
||||
} else {
|
||||
AppProvider.getRouter(context).navigateTo(context, "/Home", transition: TransitionType.fadeIn);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
38
web_native/lib/screens/TemplateScreen.dart.template
Normal file
38
web_native/lib/screens/TemplateScreen.dart.template
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TemplatesScreen extends StatefulWidget {
|
||||
static const String PATH = '/Templates';
|
||||
|
||||
TemplatesScreen({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_TemplatesScreenState createState() => _TemplatesScreenState();
|
||||
}
|
||||
|
||||
class _TemplatesScreenState extends State<TemplatesScreen> {
|
||||
|
||||
// TemplatesBloc bloc;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
// bloc.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_init();
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: Text("Templates")
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _init(){
|
||||
// if(null == bloc){
|
||||
// bloc = TemplatesBloc(AppProvider.getApplication(context));
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:imagini/blocs/login/bloc.dart';
|
||||
import 'package:imagini/blocs/login/states.dart';
|
||||
import 'package:imagini/blocs/login/events.dart';
|
||||
import 'package:imagini/blocs/theme/bloc.dart';
|
||||
import 'package:imagini/blocs/theme/events.dart';
|
||||
import 'package:imagini/settings/preferences.dart';
|
||||
import 'package:imagini/settings/app_themes.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
@override
|
||||
_LoginScreenState createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadTheme();
|
||||
_loadLogin();
|
||||
}
|
||||
|
||||
_loadTheme() async {
|
||||
context.read<ThemeBloc>().add(ThemeEvent(appTheme: Preferences.getTheme()));
|
||||
}
|
||||
|
||||
_loadLogin() async {
|
||||
context.read<LoginBloc>().add(LoginEvents.loginResult);
|
||||
}
|
||||
|
||||
_setTheme(bool darkTheme) async {
|
||||
AppTheme selectedTheme =
|
||||
darkTheme ? AppTheme.lightTheme : AppTheme.darkTheme;
|
||||
context.read<ThemeBloc>().add(ThemeEvent(appTheme: selectedTheme));
|
||||
Preferences.saveTheme(selectedTheme);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: _body(),
|
||||
);
|
||||
}
|
||||
|
||||
_body() {
|
||||
return BlocBuilder<LoginBloc, LoginState>(builder: (BuildContext context, LoginState state) {
|
||||
|
||||
// Set Theme
|
||||
_setTheme(true);
|
||||
|
||||
if (state is LoginNeeded) {
|
||||
// TODO: Load Login Form
|
||||
return Center( child: Text("Login Needed") );
|
||||
}
|
||||
if (state is LoginFailed) {
|
||||
// TODO: Update Form Failed
|
||||
return Center( child: Text("Login Failed: ${state.error.message.toString()}") );
|
||||
}
|
||||
if (state is LoginSuccess) {
|
||||
// TODO: Navigate to /Gallery
|
||||
return Center( child: Text("Login Success") );
|
||||
}
|
||||
|
||||
// TODO: Login Screen
|
||||
return Center( child: Text("Login Loading") );
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Body extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: RaisedButton(
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, '/Upload');
|
||||
},
|
||||
child: Text('Page Two!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:imagini/models/contact.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:imagini/bloc/bloc.dart';
|
||||
|
||||
class GalleryBloc extends Bloc {
|
||||
StreamSubscription _audioPlayerStateSubscription;
|
||||
|
||||
Stream<String> get example => _exampleSubject.stream;
|
||||
Sink<String> get exampleSink => _exampleSubject.sink;
|
||||
final StreamController<String> _exampleSubject = StreamController<String>();
|
||||
|
||||
GalleryBloc();
|
||||
|
||||
void dispose() {
|
||||
_exampleSubject.close();
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:imagini/screens/gallery/components/body.dart';
|
||||
import 'package:imagini/screens/gallery/gallery-bloc.dart';
|
||||
import 'package:imagini/bloc/bloc-prov.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
|
||||
|
||||
class GalleryScreen extends StatefulWidget {
|
||||
@override
|
||||
_GalleryScreenState createState() => _GalleryScreenState();
|
||||
}
|
||||
|
||||
class _GalleryScreenState extends State<GalleryScreen> {
|
||||
GalleryBloc exampleBloc;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
exampleBloc = GalleryBloc();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
exampleBloc.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
bloc: exampleBloc,
|
||||
child: PlatformScaffold(
|
||||
appBar: PlatformAppBar(
|
||||
title: Text('Gallery'),
|
||||
cupertino: (_, __) => CupertinoNavigationBarData(
|
||||
// Issue with cupertino where a bar with no transparency
|
||||
// will push the list down. Adding some alpha value fixes it (in a hacky way)
|
||||
backgroundColor: Colors.lightGreen.withAlpha(254),
|
||||
),
|
||||
),
|
||||
body: Body(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Body extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Container(
|
||||
margin: EdgeInsets.fromLTRB(50, 0, 50, 0),
|
||||
height: 500,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
child: const FlutterLogo(),
|
||||
),
|
||||
width: 175,
|
||||
margin: EdgeInsets.fromLTRB(0, 0, 0, 50),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Server Address'
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Username / Email'
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
obscureText: true,
|
||||
enableSuggestions: false,
|
||||
autocorrect: false,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Password'
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
child: RaisedButton(
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, '/Gallery');
|
||||
},
|
||||
child: Text('Login')
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:imagini/models/contact.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:imagini/bloc/bloc.dart';
|
||||
|
||||
class LoginBloc extends Bloc {
|
||||
StreamSubscription _audioPlayerStateSubscription;
|
||||
|
||||
Stream<String> get example => _exampleSubject.stream;
|
||||
Sink<String> get exampleSink => _exampleSubject.sink;
|
||||
final StreamController<String> _exampleSubject = StreamController<String>();
|
||||
|
||||
LoginBloc();
|
||||
|
||||
void dispose() {
|
||||
_exampleSubject.close();
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:imagini/screens/login/components/body.dart';
|
||||
import 'package:imagini/screens/login/login-bloc.dart';
|
||||
import 'package:imagini/bloc/bloc-prov.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
@override
|
||||
_LoginScreenState createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
LoginBloc loginBloc;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loginBloc = LoginBloc();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
loginBloc.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
bloc: LoginBloc(),
|
||||
child: Scaffold(
|
||||
// appBar: AppBar(
|
||||
// title: Text("Login"),
|
||||
// ),
|
||||
body: Body(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Body extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: RaisedButton(
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, '/Upload');
|
||||
},
|
||||
child: Text('Page Two!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:imagini/models/contact.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:imagini/bloc/bloc.dart';
|
||||
|
||||
class MeBloc extends Bloc {
|
||||
StreamSubscription _audioPlayerStateSubscription;
|
||||
|
||||
Stream<String> get example => _exampleSubject.stream;
|
||||
Sink<String> get exampleSink => _exampleSubject.sink;
|
||||
final StreamController<String> _exampleSubject = StreamController<String>();
|
||||
|
||||
MeBloc();
|
||||
|
||||
void dispose() {
|
||||
_exampleSubject.close();
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:imagini/screens/me/components/body.dart';
|
||||
import 'package:imagini/screens/me/me-bloc.dart';
|
||||
import 'package:imagini/bloc/bloc-prov.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
|
||||
|
||||
class MeScreen extends StatefulWidget {
|
||||
@override
|
||||
_MeScreenState createState() => _MeScreenState();
|
||||
}
|
||||
|
||||
class _MeScreenState extends State<MeScreen> {
|
||||
MeBloc exampleBloc;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
exampleBloc = MeBloc();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
exampleBloc.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
bloc: exampleBloc,
|
||||
child: PlatformScaffold(
|
||||
appBar: PlatformAppBar(
|
||||
title: Text('Mes'),
|
||||
cupertino: (_, __) => CupertinoNavigationBarData(
|
||||
// Issue with cupertino where a bar with no transparency
|
||||
// will push the list down. Adding some alpha value fixes it (in a hacky way)
|
||||
backgroundColor: Colors.lightGreen.withAlpha(254),
|
||||
),
|
||||
),
|
||||
body: Body(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Body extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: RaisedButton(
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, '/Upload');
|
||||
},
|
||||
child: Text('Page Two!'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:imagini/models/contact.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:imagini/bloc/bloc.dart';
|
||||
|
||||
class SettingsBloc extends Bloc {
|
||||
StreamSubscription _audioPlayerStateSubscription;
|
||||
|
||||
Stream<String> get example => _exampleSubject.stream;
|
||||
Sink<String> get exampleSink => _exampleSubject.sink;
|
||||
final StreamController<String> _exampleSubject = StreamController<String>();
|
||||
|
||||
SettingsBloc();
|
||||
|
||||
void dispose() {
|
||||
_exampleSubject.close();
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:imagini/screens/settings/components/body.dart';
|
||||
import 'package:imagini/screens/settings/settings-bloc.dart';
|
||||
import 'package:imagini/bloc/bloc-prov.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
|
||||
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
@override
|
||||
_SettingsScreenState createState() => _SettingsScreenState();
|
||||
}
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
SettingsBloc exampleBloc;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
exampleBloc = SettingsBloc();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
exampleBloc.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
bloc: exampleBloc,
|
||||
child: PlatformScaffold(
|
||||
appBar: PlatformAppBar(
|
||||
title: Text('Settings'),
|
||||
cupertino: (_, __) => CupertinoNavigationBarData(
|
||||
// Issue with cupertino where a bar with no transparency
|
||||
// will push the list down. Adding some alpha value fixes it (in a hacky way)
|
||||
backgroundColor: Colors.lightGreen.withAlpha(254),
|
||||
),
|
||||
),
|
||||
body: Body(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Body extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: RaisedButton(
|
||||
onPressed: () {
|
||||
// Back (popping)
|
||||
// Navigator.pop(context);
|
||||
|
||||
// Go to Login Screen
|
||||
Navigator.pushNamed(context, '/Login');
|
||||
},
|
||||
child: Text('Login'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:imagini/models/contact.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:imagini/bloc/bloc.dart';
|
||||
|
||||
class SplashBloc extends Bloc {
|
||||
StreamSubscription _audioPlayerStateSubscription;
|
||||
|
||||
Stream<String> get example => _exampleSubject.stream;
|
||||
Sink<String> get exampleSink => _exampleSubject.sink;
|
||||
final StreamController<String> _exampleSubject = StreamController<String>();
|
||||
|
||||
SplashBloc();
|
||||
|
||||
void dispose() {
|
||||
_exampleSubject.close();
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:imagini/models/contact.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:imagini/bloc/bloc.dart';
|
||||
|
||||
class UploadBloc extends Bloc {
|
||||
StreamSubscription _audioPlayerStateSubscription;
|
||||
|
||||
Stream<String> get example => _exampleSubject.stream;
|
||||
Sink<String> get exampleSink => _exampleSubject.sink;
|
||||
final StreamController<String> _exampleSubject = StreamController<String>();
|
||||
|
||||
UploadBloc();
|
||||
|
||||
void dispose() {
|
||||
_exampleSubject.close();
|
||||
}
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
import 'package:cross_file/cross_file.dart' show XFile;
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
|
||||
import 'package:imagini/bloc/bloc-prov.dart';
|
||||
import 'package:imagini/screens/upload/upload-bloc.dart';
|
||||
import 'package:tus_client/tus_client.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class UploadScreen extends StatefulWidget {
|
||||
@override
|
||||
_UploadScreenState createState() => _UploadScreenState();
|
||||
}
|
||||
|
||||
class _UploadScreenState extends State<UploadScreen> {
|
||||
UploadBloc exampleBloc;
|
||||
|
||||
double _progress = 0;
|
||||
XFile _file;
|
||||
TusClient _client;
|
||||
Uri _fileUrl;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
exampleBloc = UploadBloc();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
exampleBloc.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
bloc: exampleBloc,
|
||||
child: PlatformScaffold(
|
||||
appBar: PlatformAppBar(
|
||||
title: Text('Uploads'),
|
||||
cupertino: (_, __) => CupertinoNavigationBarData(
|
||||
// Issue with cupertino where a bar with no transparency
|
||||
// will push the list down. Adding some alpha value fixes it (in a hacky way)
|
||||
backgroundColor: Colors.lightGreen.withAlpha(254),
|
||||
),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
SizedBox(height: 12),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
child: Text(
|
||||
"This demo uses TUS client to upload a file",
|
||||
style: TextStyle(fontSize: 18),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(6),
|
||||
child: Card(
|
||||
color: Colors.teal,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
_file =
|
||||
await _getXFile(await FilePicker.platform.pickFiles());
|
||||
setState(() {
|
||||
_progress = 0;
|
||||
_fileUrl = null;
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Icon(Icons.cloud_upload, color: Colors.white, size: 60),
|
||||
Text(
|
||||
"Upload a file",
|
||||
style: TextStyle(fontSize: 25, color: Colors.white),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: RaisedButton(
|
||||
onPressed: _file == null
|
||||
? null
|
||||
: () async {
|
||||
// Create a client
|
||||
print("Create a client");
|
||||
_client = TusClient(
|
||||
Uri.parse("https://master.tus.io/files/"),
|
||||
_file,
|
||||
store: TusMemoryStore(),
|
||||
);
|
||||
|
||||
print("Starting upload");
|
||||
await _client.upload(
|
||||
onComplete: () async {
|
||||
print("Completed!");
|
||||
setState(() => _fileUrl = _client.uploadUrl);
|
||||
},
|
||||
onProgress: (progress) {
|
||||
print("Progress: $progress");
|
||||
setState(() => _progress = progress);
|
||||
},
|
||||
);
|
||||
},
|
||||
child: Text("Upload"),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: RaisedButton(
|
||||
onPressed: _progress == 0
|
||||
? null
|
||||
: () async {
|
||||
_client.pause();
|
||||
},
|
||||
child: Text("Pause"),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Stack(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
padding: const EdgeInsets.all(1),
|
||||
color: Colors.grey,
|
||||
width: double.infinity,
|
||||
child: Text(" "),
|
||||
),
|
||||
FractionallySizedBox(
|
||||
widthFactor: _progress / 100,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
padding: const EdgeInsets.all(1),
|
||||
color: Colors.green,
|
||||
child: Text(" "),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.all(8),
|
||||
padding: const EdgeInsets.all(1),
|
||||
width: double.infinity,
|
||||
child: Text("Progress: ${_progress.toStringAsFixed(1)}%"),
|
||||
),
|
||||
],
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: _progress != 100
|
||||
? null
|
||||
: () async {
|
||||
await launch(_fileUrl.toString());
|
||||
},
|
||||
child: Container(
|
||||
color: _progress == 100 ? Colors.green : Colors.grey,
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
margin: const EdgeInsets.all(8.0),
|
||||
child:
|
||||
Text(_progress == 100 ? "Link to view:\n $_fileUrl" : "-"),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<XFile> _getXFile(FilePickerResult result) async {
|
||||
if (result != null) {
|
||||
final chosenFile = result.files.first;
|
||||
if (chosenFile.path != null) {
|
||||
// Android, iOS, Desktop
|
||||
return XFile(chosenFile.path);
|
||||
} else {
|
||||
// Web
|
||||
return XFile.fromData(
|
||||
chosenFile.bytes,
|
||||
name: chosenFile.name,
|
||||
);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user