mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Add user panel
This commit is contained in:
		@@ -1,4 +1,5 @@
 | 
			
		||||
import 'package:comunic/ui/routes/main_route/main_route.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/tablet_mode/current_user_panel.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
/// Main tablet route
 | 
			
		||||
@@ -32,9 +33,16 @@ class _TabletRouteState extends State<TabletRoute> {
 | 
			
		||||
        children: <Widget>[_buildLeftPane(), _buildRightPane()],
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  Widget _buildLeftPane() => Container(
 | 
			
		||||
        width: 300,
 | 
			
		||||
        color: Color(0xFF222D32),
 | 
			
		||||
  Widget _buildLeftPane() => Theme(
 | 
			
		||||
        data: Theme.of(context).copyWith(
 | 
			
		||||
            textTheme: TextTheme(body1: TextStyle(color: Colors.white))),
 | 
			
		||||
        child: Container(
 | 
			
		||||
          width: 300,
 | 
			
		||||
          color: Color(0xFF222D32),
 | 
			
		||||
          child: Column(
 | 
			
		||||
            children: <Widget>[CurrentUserPanel()],
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
  Widget _buildRightPane() => Container();
 | 
			
		||||
 
 | 
			
		||||
@@ -42,4 +42,14 @@ abstract class SafeState<T extends StatefulWidget> extends State<T> {
 | 
			
		||||
      setState(() => onEvent(d));
 | 
			
		||||
    }));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Safely mimic the setTimeout javascript function
 | 
			
		||||
  ///
 | 
			
		||||
  /// If the widget is unmounted before the end of the timeout,
 | 
			
		||||
  /// the callback function is not called
 | 
			
		||||
  void setTimeout(int secs, void Function() cb) {
 | 
			
		||||
    Timer(Duration(seconds: secs), () {
 | 
			
		||||
      if (!_unmounted) cb();
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										58
									
								
								lib/ui/widgets/tablet_mode/current_user_panel.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								lib/ui/widgets/tablet_mode/current_user_panel.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
import 'package:comunic/helpers/users_helper.dart';
 | 
			
		||||
import 'package:comunic/models/user.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/account_image_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/safe_state.dart';
 | 
			
		||||
import 'package:comunic/utils/account_utils.dart';
 | 
			
		||||
import 'package:comunic/utils/ui_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
/// Current user panel
 | 
			
		||||
///
 | 
			
		||||
/// @author Pierre HUBERT
 | 
			
		||||
 | 
			
		||||
class CurrentUserPanel extends StatefulWidget {
 | 
			
		||||
  @override
 | 
			
		||||
  _CurrentUserPanelState createState() => _CurrentUserPanelState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _CurrentUserPanelState extends SafeState<CurrentUserPanel> {
 | 
			
		||||
  User _user;
 | 
			
		||||
 | 
			
		||||
  Future<void> _refresh() async {
 | 
			
		||||
    try {
 | 
			
		||||
      final user = await UsersHelper().getSingleWithThrow(userID());
 | 
			
		||||
 | 
			
		||||
      setState(() => _user = user);
 | 
			
		||||
    } catch (e, s) {
 | 
			
		||||
      print("Could not load user panel! $e\n$s");
 | 
			
		||||
 | 
			
		||||
      setTimeout(5, _refresh);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    super.initState();
 | 
			
		||||
    _refresh();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return Container(
 | 
			
		||||
      height: 80,
 | 
			
		||||
      child: Center(child: _buildContent()),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Widget _buildContent() {
 | 
			
		||||
    if (_user == null) return buildCenteredProgressBar();
 | 
			
		||||
 | 
			
		||||
    return ListTile(
 | 
			
		||||
      leading: AccountImageWidget(
 | 
			
		||||
        user: _user,
 | 
			
		||||
        width: 50,
 | 
			
		||||
      ),
 | 
			
		||||
      title: Text(_user.displayName),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user